这个脚本有点倒退,因为它需要返回用户所属的所有组。我让脚本工作,但它只返回导入文件中第一个用户的组,并为每个其他用户复制相同的组。
输入内容的示例:
"NetworkID","DisplayName"
"jasonid",Jason
anotherid
"mikeid","Mens, Mike"
我对 powershell(带有 AD 模块的第 2 版)相对较新,因此将不胜感激。这是我创建的脚本:
$out = @()
Import-Csv "$env:userprofile\Desktop\ADUsers.txt" | SELECT NetworkID | ForEach {
$NetworkIDs = $_
ForEach ($NetworkID in $NetworkIDs)
{
ForEach ($group in $groups)
{
$obj = New-Object -TypeName PSObject
$obj | Add-Member -MemberType NoteProperty -Name UserName -Value $NetworkIDs.NetworkID
$obj | Add-Member -MemberType NoteProperty -Name GroupName -Value $group.name
$out += $obj
}
}
}
$out | Format-table -AutoSize
$out | Export-Csv -path $env:userprofile\Desktop\ADUsers.csv –NoTypeInformation
输出的一个例子是:
"UserName","GroupName"
"jasonid","Domain Group 1"
"jasonid","Domain Group 2"
"jasonid","Domain Group 3"
"anotherid","Domain Group 1"
"anotherid","Domain Group 2"
"anotherid","Domain Group 3"
"mikeid","Domain Group 1"
"mikeid","Domain Group 2"
"mikeid","Domain Group 3"
我 100% 确信“jasonid”是所有 3 个组的成员,“anotherid”不是“Domain Group 1”的成员,“mikeid”不是“Domain Group 3”的成员。