我正在尝试编写一个脚本,用于检查字符串是否为空,以及是否将用户名输出到文件中,以便我可以返回并检查该文件并查看谁为null。下面是我的代码,脚本没有写出任何想法的文件?
$user = "user@domain.com"
#just gets the users info
$user_info = gam info user $user
$suspended = $user_info | Select-String -pattern "Account Suspended: true"
if ($suspended = $null) {
$user | Out-File -FilePath C:\scripts\not_suspended.txt -append -Encoding utf8
}
答案 0 :(得分:5)
您正在if语句中为$null
分配$suspended
。请使用-eq
代替进行比较:
if ($suspended -eq $null) {
$user | Out-File -FilePath C:\scripts\not_suspended.txt -append -Encoding utf8
}