How could I deal with conditional formatting ? Expression = {}

Daoust ICT
Daoust ICT used Ask the Experts™
on
Considering this command
                                                            @{ name = "Router_0"; expression = { "<a href=http://" + $_.Router_0 + ">" + $_.Router_0 + "</a>" } }, `
How could I deal with conditional formatting ?


type if router_0 eq "" then no hyperlink or
if router_0  eq "10.1.1.254" red color
tks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
It's an expression, so you have the full power of PowerShell at your disposal. You just need to make sure that the expression returns the string you want:
...
@{name = "Router_0"; expression = {
	If ($_.Router_0 -eq '10.1.1.254') {
		"<a href=http://$($_.Router_0)><font color=`"red`">$($_.Router_0)<font color=`"red`"></a>"
	} ElseIf ($_.Router_0) {
		"<a href=http://$($_.Router_0)>$($_.Router_0)</a>"
	} Else {
		'n/a'
	}
}},
...

Open in new window


And note that if you have a Select-Object with multiple properties that you want to spread out over multiple lines, it's enough to end the lines with a comma; you don't need a backtick after the comma.
... | Select-Object -Property `
	Prop1,
	Prop2,
	Prop3

Open in new window

Daoust ICTIcT service Desk

Author

Commented:
what's wrong ?

                                                                                @{ name = "$strDateValueLabel"; expression = `
                              { `
                                    If (ConvertYYYYMMDDtoDate $_.DateValue -ge Get-Date) `
                                          { "<font color=`"red`">" + $_.DateValue.Substring(6, 2) + "/" + $_.DateValue.Substring(4, 2) + "/" + $_.DateValue.Substring(0, 4) + "<font color=`"red`">"} `
                                    elseif (((ConvertYYYYMMDDtoDate $_.DateValue) - (Get-Date)).days -eq 1) `
                                    { "<font color=`"Orange`">"+ $_.DateValue.Substring(6, 2) + "/" + $_.DateValue.Substring(4, 2) + "/" + $_.DateValue.Substring(0, 4) + "<font color=`"Orange`">" } `
                                    Else { $_.DateValue.Substring(6, 2) + "/" + $_.DateValue.Substring(4, 2) + "/" + $_.DateValue.Substring(0, 4)} `
                              }
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
Can't tell. Wrap the the content of the expression into a Try {} block and, and write the exception to the console using Write-Host in the Catch {} block.
@{name = $strDateValueLabel; expression = {
	Try {
		...
	} Catch {
		$_ | Out-String | Write-Host -Fore Yellow
	}
}}

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial