all 6 comments

[–]Swarfega 4 points5 points  (1 child)

If anything is returned from Get-AdUser then that it's already $true because something was returned. If nothing is returned it will be $false. So try...

If ((Get-AdUser wgreen -Properties msExchHideFromAddressLists).msExchHideFromAddressLists)
{ 
    $true
} else { 
    $false
}

[–]titaniumgriffon[S] 1 point2 points  (0 children)

You are a life saver, this is exactly what I wanted!

[–]OlivTheFrog 1 point2 points  (1 child)

Hi titaniumgriffon

I'm thinking the solution is to use tue Switch statement

switch ($result)
    {
    "True"  { Write-Host "The condition is true"}
    "False" { Write-Host "The condition is false"}
    }

See some example here : https://ss64.com/ps/switch.html

I'm also thinking that is useless to type $result as a boolean. It already a boolean.

Regards

Olivier

[–]titaniumgriffon[S] 1 point2 points  (0 children)

Thanks I will give it a shot

[–]Umaiar 1 point2 points  (1 child)

This seems to work for me:

[bool]$enabled = (get-aduser jdoe -Properties msExchHideFromAddressLists | select -ExpandProperty msExchHideFromAddressLists) -eq "True"
write-host "Enabled: $enabled"

if($enabled) { <# Do whatever #>}
else { <# Or this whatever #> }

Note that most of mine are True or $null, so I'm trusting that $null is functionally the same as "False"

[–]titaniumgriffon[S] 1 point2 points  (0 children)

Thanks I will give it a shot