Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 }
Copy link

joswr1ght commented May 26, 2020

GCI -Path "C:\temp" | Where-Object {$_.Length -eq 0} |Remove-Item - Remove 0-byte files

Copy link

maiooo13 commented May 26, 2020

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

Copy link

funkwhatyouheard commented Jul 7, 2020

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