I am currently developing and consolidating my PowerShell skills and needed help for my script.
I want to retrieve only the result / value "true / false" of the object rather than the description followed by the result of value "true / false".
It will be clearer with my code :
$moreadlock = get-aduser -identity fferman -properties * | select lastbadpasswordattempt, lastlogondate, lockedout, passwordexpired, passwordlastset | format-list
$sAMAccountName = Read-Host "Username"
if ( $null -ne ([ADSISearcher] "(sAMAccountName=$sAMAccountName)").FindOne() -eq $true ) {
Write-Host "Exist."
Write-Host ""
Write-Host "Additional information about the selected user : "
$moreadlock
AND at this level, I would like to implement a condition : If the value of "lockedout" is true, propose an unblocking of the account in the AD
if ( $lockedout -eq $true ) {
Write-Host "Account locked."
With, after asking the user something like that :
$qunlock = Read-Host "Unlock account ?"
if ( $qunlock -eq $true ) {
Unlock-AdAccount }
The problem being that using the command:
$test=get-aduser -identity user -properties * | Select-Object -Property lockedout
$test
This returns me:
lockedout
---------
False
And not the result of the value itself, "false".