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

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 "" red color
François VDCIcT service DeskAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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 '') {
		"<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 {

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 `

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
François VDCIcT service DeskAuthor 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)} `
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

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.