T.Scott
T.Scott

Reputation: 11

Combining get-aduser and get-qadmemberof

I am trying to combine these two entries... get-aduser XXXX | select name,givenname,surname and get-qadmemberof -identity XXXX | select name | sort name they both work fine but I want to combine so my results will show the user's name and below that the groups that the user is in.

Upvotes: 1

Views: 1819

Answers (2)

Lachie White
Lachie White

Reputation: 1251

A few ways this can be achieved.

Way 1:

#Output will resemble "CN=GroupName,OU=Groups,OU=Domain,OU=Local" Not always ideal output
Get-ADUser -Identity "TestUser" -Properties -ExpandProperty MemberOf

Way 2: As Kevin Mentioned

#Output will resemble more what you are looking for
Get-ADUser -Identity "TestUser" | Get-ADPrincipalGroupMembership | Select-Obeject -ExpandProperty Name

Way 3: Full Script

#This will create a csv titled with the Users sAMAccountName from the .txt file, 
#within that csv is a list of the users groups.
#To improve on this script you could use PSObjects to make this more efficent
#Don't Want to give you all the answers ;)

Import-Module ActiveDirectory
$UserList = Get-Content C:\Temp\UserList.txt
ForEach($User in $UserList){
  $UserMembership = Get-ADUser $User | Get-ADPrincipalGroupMembership | Select-Object -Property Name
  $UserMembership | Export-CSV "C:\Temp\$User.CSV" -NoTypeInformation
}

Upvotes: 0

Kevin Olson
Kevin Olson

Reputation: 1

Get-Aduser XXXX | Get-ADPrincipalGroupMembership | select name

This is how to get group names for "XXXX" with Microsoft Native AD module.

Upvotes: 0

Related Questions