0phoi5 Posted July 10, 2017 Share Posted July 10, 2017 (edited) Why is the below not working correctly? It should Write-Host 'Active', but it doesn't? PS C:\Windows\system32> $(Get-ADUser JoeBloggs -Properties *).PasswordExpired False PS C:\Windows\system32> if ($(Get-ADUser JoeBloggs -Properties *).PasswordExpired -eq "False") { Write-Host "Active" } else { Write-Host "Locked" } Locked Thanks. Edited July 10, 2017 by haze1434 Quote Link to comment Share on other sites More sharing options...
PoSHMagiC0de Posted July 10, 2017 Share Posted July 10, 2017 Not on an AD system at the moment but try one of these 2 things. Instead of testing for "false", test for $false. Try removing the "$" from the encapsulated get-aduser command. I know it shouldn't make a difference but I seen Posh react differently to certain things in certain situations so trying it doesn't hurt. When I get into the office I will try and replicate your situation in my test AD environment. Quote Link to comment Share on other sites More sharing options...
0phoi5 Posted July 10, 2017 Author Share Posted July 10, 2017 Ah, bingo. Using -eq $false worked. Strange how -eq "False" didn't work when PasswordExpired confirmed that was it's exact state. Any idea why it does this? Thank you, appreciated. Should have worked that out myself, but man has it been a busy day! Quote Link to comment Share on other sites More sharing options...
PoSHMagiC0de Posted July 11, 2017 Share Posted July 11, 2017 9 hours ago, haze1434 said: Ah, bingo. Using -eq $false worked. Strange how -eq "False" didn't work when PasswordExpired confirmed that was it's exact state. Any idea why it does this? Thank you, appreciated. Should have worked that out myself, but man has it been a busy day! I bet if you got the type, it would be a type boolean. If so then you would have had to add a ".tostring()" to the end to make it equal the string of "False". Quote Link to comment Share on other sites More sharing options...
Dave-ee Jones Posted July 11, 2017 Share Posted July 11, 2017 1 hour ago, PoSHMagiC0de said: I bet if you got the type, it would be a type boolean. If so then you would have had to add a ".tostring()" to the end to make it equal the string of "False". Correct :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.