带变量的Powershell Out文件
我正在尝试编写一个脚本,该脚本将检查字符串是否为null,以及是否将用户名输出到一个文件,以便我可以返回并检查该文件,并查看谁为null。下面是我的代码,脚本是不是写出来的文件有什么想法带变量的Powershell Out文件,powershell,if-statement,Powershell,If Statement,我正在尝试编写一个脚本,该脚本将检查字符串是否为null,以及是否将用户名输出到一个文件,以便我可以返回并检查该文件,并查看谁为null。下面是我的代码,脚本是不是写出来的文件有什么想法 $user = "user@domain.com" #just gets the users info $user_info = gam info user $user $suspended = $user_info | Select-String -pattern "Account Suspended: t
$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
}
您正在if语句中将
$null
赋值给$suspended
。使用-eq
进行比较:
if ($suspended -eq $null) {
$user | Out-File -FilePath C:\scripts\not_suspended.txt -append -Encoding utf8
}
您正在if语句中将
$null
赋值给$suspended
。使用-eq
进行比较:
if ($suspended -eq $null) {
$user | Out-File -FilePath C:\scripts\not_suspended.txt -append -Encoding utf8
}