PowerShell script to return members of multiple security groups

后端 未结 4 1771
感情败类
感情败类 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 21:50

    This will give you a list of a single group, and the members of each group.

    param
    (   
        [Parameter(Mandatory=$true,position=0)]
        [String]$GroupName
    )
    
    import-module activedirectory
    
    # optional, add a wild card..
    # $groups = $groups + "*"
    
    $Groups = Get-ADGroup -filter {Name -like $GroupName} | Select-Object Name
    
    ForEach ($Group in $Groups)
       {write-host " "
        write-host "$($group.name)"
        write-host "----------------------------"
    
        Get-ADGroupMember -identity $($groupname) -recursive | Select-Object samaccountname
    
     }
    write-host "Export Complete"
    

    If you want the friendly name, or other details, add them to the end of the select-object query.

提交回复
热议问题