PowerShell script to return members of multiple security groups

后端 未结 4 1725
感情败类
感情败类 2021-01-17 21:32

I need to return all members of multiple security groups using PowerShell. Handily, all of the groups start with the same letters.

I can return a list of all the rel

4条回答
  •  走了就别回头了
    2021-01-17 22:10

    If you don't care what groups the users were in, and just want a big ol' list of users - this does the job:

    $Groups = Get-ADGroup -Filter {Name -like "AB*"}
    
    $rtn = @(); ForEach ($Group in $Groups) {
        $rtn += (Get-ADGroupMember -Identity "$($Group.Name)" -Recursive)
    }
    

    Then the results:

    $rtn | ft -autosize
    

提交回复
热议问题