本文共 1077 字,大约阅读时间需要 3 分钟。
我是相当新的PS用户...寻找PowerShell脚本的一些帮助,以获取用户所属的安全组列表 .
描述我需要的东西:
我有许多用户的输入列表(txt文件)(samaccountnames) . 每个名字都在新的一行上 .
我需要脚本在AD中搜索这些名称 - 整个林,而不仅仅是一个域
输出应该看起来像"samaccountname"这个帐户所属的组列表在一行中,所以我可以在excel中对它进行排序
这是我的脚本:
$users = Get-Content C:\users.txt
ForEach ($User in $users) {
$getmembership = Get-ADUser $User.Users -Properties MemberOf | Select -ExpandProperty memberof
$getmembership | Out-File -Append c:\membership.txt
}
但它给我一个错误:
Get-ADUser : Cannot validate argument on parameter 'Identity'. The argument is null. Supply a non-null argument and try the command again.
At line:4 char:28
+ $getmembership = Get-ADUser <<<< $User.Users -Properties MemberOf | Select -ExpandProperty memberof
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
无论如何,这个脚本不会搜索整个森林 .
样本输入列表:
username1
username2
username3
username4... etc
示例输出列表
username1;group1;group2;group3
username2;group1;group2;group3;group4... etc or something similar
任何帮助将不胜感激 .
转载地址:https://blog.csdn.net/weixin_33212263/article/details/114244507 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!