2016-12-15 27 views
0

我想將這兩個條目組合起來...... get-aduser XXXX |選擇姓名,姓名,姓 和 get-qadmemberof -identity XXXX |選擇名稱|排序名稱 他們都工作得很好,但我想結合,所以我的結果將顯示用戶名和低於該用戶在組。組合get-aduser和get-qadmemberof

+0

你爲什麼想這樣做? 'get-aduser XXXX -Properties memberof' – 4c74356b41

回答

0
Get-Aduser XXXX | Get-ADPrincipalGroupMembership | select name 

這是如何獲得「XXXX」組名與Microsoft Native AD模塊。

0

有幾種方法可以實現。

方式1:

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

方式2:作爲凱文提到

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

方式3:全腳本

#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 
}