首页 > 解决方案 > Send Message if Account is Locked Out

问题描述

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!

标签: powershell

解决方案


检查"false"字面意思是查找单词 false。在 Powershell 中,您需要$false根据以下更新的代码进行检查:

  $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')}

或者使用-not $u.LockedOut


推荐阅读