Created
June 13, 2018 14:51
-
-
Save danielchc/922b95e5ce0f12a2f66ba4e59b2f9e4b to your computer and use it in GitHub Desktop.
List members from AD Security Group (without "Domain *" groups)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param([String]$FileName='ADGroups.csv') | |
Import-Module ActiveDirectory 2>$nul | |
$groups=ForEach ($i in Get-ADGroup -Filter 'groupcategory -eq "security"' -searchbase "OU=Domain Users,dc=ORGANITATION,dc=local" | Where-Object { !($_.Name -like "*Domain*")} ){ | |
Get-ADGroupMember $i | Where-Object {($_.objectClass -eq "user")} | Select @{n='DistributionName';e={$i.Name}},Name,SamAccountName | |
} | |
$groups |Export-CSV $FileName -NoTypeInformation -Encoding UTF8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment