Send Message if Account is Locked Out

Viewed 53

currently I'm creating a script that will at the moment just return a message if an Account is not locked out, and .LockedOut = "False". All the accounts i'm running have False as their LockedOut status, however it's not returning the message in my if statement like I would hope.

$user1 = $env:USERNAME
$u = Import-Csv C:\Users\$user1\Documents\ServiceAccts.csv | ForEach-Object{ Get-ADUser $_.User -Properties *}
#Run write-output to display AD info
#write-output $u
if ($u.LockedOut -eq "False") {[System.Windows.MessageBox]::Show('Not Locked')}

So I'm just hoping that for each one that equals false for it to display the message box at the moment. I was hoping you guys could help me out and see if anything is wrong with my If statement. Thanks!

1 Answers

Checking for "false" literally looks for the word false. In Powershell you need to check against $false as per the updated code below:

  $user1 = $env:USERNAME
    $u = Import-Csv C:\Users\$user1\Documents\ServiceAccts.csv | ForEach-Object{ Get-ADUser $_.User -Properties *}
    #Run write-output to display AD info
    #write-output $u
    if ($u.LockedOut -eq $false) {[System.Windows.MessageBox]::Show('Not Locked')}

Alternatively use -not $u.LockedOut

Related