Sign in to follow this  
Followers 0
haze1434

[PowerShell] if Get-ADUser not working as expected

5 posts in this topic

Posted (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 by haze1434
0

Share this post


Link to post
Share on other sites

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.

 

0

Share this post


Link to post
Share on other sites

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!

0

Share this post


Link to post
Share on other sites
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".

2

Share this post


Link to post
Share on other sites
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 :)

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.