Jump to content

[PowerShell] if Get-ADUser not working as expected


0phoi5

Recommended Posts

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
Link to comment
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.

 

Link to comment
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!

Link to comment
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".

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...