Welcome to the forums.
When you post code, error messages, sample data or console output format it as code, please.
Here you can read how that works: Guide to Posting Code.
You can go back and edit your existing post. You don’t have to create a new one. ![]()
Thanks in advance.
To check a boolean you should not use -match with “false”. Try it this way.
$user = Read-Host 'Enter Username'
$status = Get-ADUser $user -Properties LockedOut | Select-Object LockedOut
If (-not $status.LockedOut) {
'Account is Unlocked'
}
else {
Unlock-ADAccount $user
}
Why would you like to check again? Don’t you trust your code enough? ![]()
You could add the paramter -PassThru to your Unlock-ADAccount command and check its state if you need to.