我有一个文件上的活动目录计算机列表,我想看到它们中的每一个,它们属于哪些组。手动操作200-300时很长,但我认为使用脚本需要几秒钟。我将衷心感谢您的帮助。我在寻求帮助之前尝试了搜索,但我找不到我想要的东西:(
假设:您真的在寻找计算机而不是使用这些计算机的用户。将计算机分组不太常见。
如果计算机文件只是一个平面记事本文件,则每行1个系统。
这将使您获得所有相关团体的CN。
$AllSystems = Get-Content ".\CompList.txt"
foreach($OneSystem in $AllSystems)
{
write-host $OneSystem -foreground yellow
Get-ADComputer -Filter {name -eq $OneSystem} -properties * | select -ExpandProperty Memberof
}
您的输出将是机器名称(黄色),后面是机器所在的所有组的列表。
如果您想要更友好的群组名称,请尝试以下方法:
$AllSystems = Get-Content ".\CompList.txt"
foreach($OneSystem in $AllSystems)
{
write-host $OneSystem -foreground yellow
Get-ADComputer -Filter {name -eq $OneSystem} -properties * | select -ExpandProperty Memberof| %{get-adgroup -identity $_} | select name
}