检查用户是否是广告组的成员-PowerShell
我有一个带有用户名列表的TXT文件,我想检查这些用户是否是特定AD组的成员。如果他们不是该组的成员,则必须将其用户名编写在CSV文件中。因此,输出应该是一个CSV文件,其中没有指定的AD组中的所有用户名。
我总是会遇到“与要处理请求的目录连接的连接。这可能是瞬态条件。”目录模块与AD创建连接。
这是我的简短脚本:
$userlist = get-content -Path "C:\Temp\users.txt"
$group = "group_xy"
$result = foreach ($user in $userlist)
{
$groupmembers = Get-ADgroup -Filter {Name -eq $group}|Get-ADGroupMember
if ($groupmembers.samaccountname -notmatch $users){
[PSCustomObject]@{
Name = $user
Group = $group
Member = 'False'
}
}
}
$result |Export-csv "C:\Temp\Result.csv" -NoTypeInformation
我该如何解决?
br
i have a txt file with a list of usernames and I want to check if these users are a member of a specific AD-group. If they aren't a member of this group, their username has to be written in a csv file. So the output should be a csv file with all usernames who are not in the specified AD-group.
I always get the error "A connection to the directory on which to process the request was unavailable. This is likely a transient condition".The error is reproduced when implementing a workflow that triggers up to 20 powershell sessions to run, each importing the Active Directory module to create a connection with AD.
This is my short script:
$userlist = get-content -Path "C:\Temp\users.txt"
$group = "group_xy"
$result = foreach ($user in $userlist)
{
$groupmembers = Get-ADgroup -Filter {Name -eq $group}|Get-ADGroupMember
if ($groupmembers.samaccountname -notmatch $users){
[PSCustomObject]@{
Name = $user
Group = $group
Member = 'False'
}
}
}
$result |Export-csv "C:\Temp\Result.csv" -NoTypeInformation
How can I solve this?
BR
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该
这样
Should be
Since you never define
$users
I think this is the error