Export User and Memberhip List in AD

teksolgreg
teksolgreg used Ask the Experts™
on
Export a list of users and their membership on an AD
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
PowerShell:
Get-ADUser -Filter * -Property memberOf | ForEach-Object {
	$adUser = $_
	$_.memberOf |
		Get-ADGroup |
		Select-Object -Property @{n='UserID'; e={$adUser.SamAccountName}}, @{n='UserDN'; e={$adUser.DistinguishedName}}, @{n='GroupID'; e={$_.SamAccountName}}, @{n='GroupDN'; e={$_.DistinguishedName}}
} | Export-Csv -NoTypeInformation -Path 'C:\Temp\Groups.csv'

Open in new window

Author

Commented:
It was pretty darn close, but my description was not perfect. I was hoping to pull, user and each group they belong to respectively.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial