Get-Adgroupmember for all groups

huangapple go评论54阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年3月23日 12:21:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75819223.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定