Tag Archives: Get-MembersInADGroups

A friend of mine asked me a couple of days ago if I knew a way to gather users who are members of given groups. I thought to myself “Hmm, challenge accepted!” and started writing a small powershell script. After he confirmed that the script worked as planned I decided to make a function of it (Yes, I know it has been a lot of them on this blog lately). The function accepts two parameters: GroupNames and Filelocation. In addition there is an optional switch called KeepCSV. Rest of the function isn’t that interesting, if you want to use it you can always consult the help (get-help get-membersinadgroups) that I actually have created 🙂 Heres the code: function Get-MembersInADGroups { Param ( [parameter(Mandatory=$True)][string[]]$GroupNames, [parameter(Mandatory=$True)][string[]]$Filelocation, [switch]$KeepCSV ) Get-ADGroup -LDAPFilter “(name=$GroupNames)” | export-csv $FileLocationtemp.csv -NoTypeInformation $groups = Import-Csv $FileLocationtemp.csv $groups | ForEach-Object { $groupname = $_.SamAccountname Get-ADGroupMember -Identity $_.SamAccountName | select-object name,samaccountname…

Read more

1/1