英文:
Get-Adgroupmember for all groups
问题
I have test group, user group, admin group in an OU, and I'm trying to get all members listed in all the groups. when I run the following code, I get "The size limit for this request was exceded". Is there a workaround for this error?
$Groups = Get-ADGroup -Filter {GroupScope -eq 'Global' -and Members -ne "NULL";}
$Users = foreach( $Group in $Groups ){
Get-ADGroupMember -Identity $Group | foreach {
[PSCustomObject]@{
Group = $Group.Name
UserName = $_.SamAccountName
}
}
}
$Users | Export-CSV C:\scripts\groups.csv -NoTypeInformation
Thanks very much.
英文:
I have test group, user group, admin group in an OU, and I'm trying to get all members listed in all the groups. when I run the following code, I get "The size limit for this request was exceded". Is there a workaround for this error?
$Groups = Get-ADGroup -Filter {GroupScope -eq 'Global' -and Members -ne "NULL"}
$Users = foreach( $Group in $Groups ){
Get-ADGroupMember -Identity $Group | foreach {
[PSCustomObject]@{
Group = $Group.Name
UserName = $_.SamAccountName
}
}
}
$Users | Export-CSV C:\scripts\groups.csv -NoTypeInformation
Thanks very much
答案1
得分: 0
尝试使用 Get-ADObject
而不是 Get-ADGroupMember
来执行您的查询:
Get-ADGroup -LDAPFilter '(&(groupType:1.2.840.113556.1.4.803:=2)(member=*))' |
ForEach-Object {
$filter = '(memberof={0})' -f $_.DistinguishedName
foreach($obj in Get-ADObject -LDAPFilter $filter -Properties samAccountName) {
[PSCustomObject]@{
Group = $_.Name
UserName = $obj.SamAccountName
}
}
} | Export-CSV C:\scripts\groups.csv -NoTypeInformation
英文:
Try using Get-ADObject
instead of Get-ADGroupMember
to perform your query:
Get-ADGroup -LDAPFilter '(&(groupType:1.2.840.113556.1.4.803:=2)(member=*))' |
ForEach-Object {
$filter = '(memberof={0})' -f $_.DistinguishedName
foreach($obj in Get-ADObject -LDAPFilter $filter -Properties samAccountName) {
[PSCustomObject]@{
Group = $_.Name
UserName = $obj.SamAccountName
}
}
} | Export-CSV C:\scripts\groups.csv -NoTypeInformation
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论