powershell - 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!
解决方案
检查"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
推荐阅读
- node.js - 来自 Vue/Nuxt 应用程序的 axios 请求超时,服务器没有响应,但相同的 Curl 请求得到响应
- azure - 无效资源 AADSTS500011
- python - minus between 2 dataframe based on column
- javascript - 将数据从 Angular 防护传递到组件失败
- angular - primeng p-upload 图标是错误的
- arrays - 实现按日期排序在 mongo 中添加
- c# - 在插入语句期间出现异常后无法删除 SQL 数据库
- typescript - 使用反射元数据访问类装饰器参数
- django - 我不明白 sorl-thumbnail 如何使用 db 和缓存
- google-cast - 是否可以使用 Google Cast API 在 google home/cast 设备中返回之前的投射会话