Tuesday, January 20, 2015

Export user and group memberships to CSV

Get-ADUser -LDAPFilter "(name=*)" -SearchScope Subtree `
-SearchBase "OU=path,OU=path,DC=path,DC=path,DC=path" | %{
$user = $_
$user | Get-ADPrincipalGroupMembership |
Select @{N="User";E={$user.sAMAccountName}},@{N="Group";E={$_.Name}}
}| Select User,Group | Export-Csv C:\Temp\Report.csv -nti

1 comment:

  1. Change the wildcard in "(name=*)" to for example QUSR to find all groups and users starting with these letters.

    ReplyDelete