Skip to content

Instantly share code, notes, and snippets.

@joswr1ght
Created January 8, 2020 13:08
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save joswr1ght/c557f8627832d54458c810e43be9c055 to your computer and use it in GitHub Desktop.
Save joswr1ght/c557f8627832d54458c810e43be9c055 to your computer and use it in GitHub Desktop.
Create a Collection of Files for Windows Domain Groups with User Members in Each File
Get-AdGroup -Filter * | % { Get-AdGroupMember $_.Name | Select-Object -ExpandProperty SamAccountName | Out-File -FilePath "$($_.Name).txt" -Encoding ASCII }
@maiooo13
Copy link

hi please can you guide me if i need to add also GroupCategory beside SamAccountName?
Thank you

@funkwhatyouheard
Copy link

Dealing with some big groups... ran into this error: Get-AdGroupMember : The size limit for this request was exceeded

Looks like there's a cap on size for Get-AdGroupMember and a few other ADWS cmdlets, but Get-AdUser is excluded from that. Tweaked the script. It'll do the same thing but doesn't care about size. Mind you, this will be quite a bit slower as it's not the pinnacle of efficiency.

Get-AdGroup -Filter * | % { Get-ADUser -LDAPFilter ("(&(objectCategory=user)(memberof={0}))" -f $.DistinguishedName) | Select-Object -ExpandProperty SamAccountName | Out-File -FilePath "$($.Name).txt" -Encoding ASCII }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment