【发布时间】:2019-02-15 00:14:43
【问题描述】:
我正在编写一个 powershell 脚本,该脚本使用我们的 AD 验证 CSV,找到当前禁用的帐户列表,然后将它们导出到另一个 CSV。我目前能够读取 CSV、比较和导出所有帐户的列表,其中包含有关其状态的真/假标志。我还可以使用另一个脚本过滤该输出 CSV。理想情况下,我想将这些合并到一个只有一个输出 CSV 的脚本中。我只是不知道该怎么做。
我尝试将脚本 2 的“where...”部分移动到脚本 1 中,但没有成功。
脚本 1:
Import-Csv C:\ServerScripts\Compare\students.csv | ForEach-Object {
New-Object -TypeName PSCustomObject -Property @{
samaccountname = $_.samaccountname
firstname = $_.firstname
lastname = $_.lastname
name = $_.name
password = $_.password
email = $_.email
description = $_.description
CAMPUS_ID = $_.CAMPUS_ID
exist = [bool]($account=([adsisearcher]"(samaccountname=$($_.samaccountname))").findone())
disabled = [bool]($account.properties.useraccountcontrol[0] -band 2)
}
} | Export-Csv C:\ServerScripts\Compare\output.csv -NoTypeInformation
脚本 2:
Import-Csv C:\ServerScripts\Compare\output.csv | where {$_.disabled -ne "FALSE"} | Export-Csv C:\ServerScripts\Compare\disabled.csv -notypeinfo
两个脚本独立工作,我只需要一种方法将它们组合在一起。
【问题讨论】:
-
问题先生,您只需要一个包含禁用用户的输出文件吗?
-
是的,这就是目标。
标签: powershell