我一直在嘗試使用下面的代碼來獲取目標計算機所在的AD組的列表,但我遇到了一些困難。Powershell - 獲取和組織機器的Active Directory組
Get-AdComputer -Identity $hostname -property "MemberOf"
當我執行代碼時,我回來了這個。
DistinguishedName : CN=$hostname,OU=test,OU=test,OU=test All Workstations,DC=te
st,DC=test,DC=com
DNSHostName : $hostname Enabled : True
MemberOf : {CN=Flash_Player_Adobe_11.1.102_LCL,OU=test All Softw
are Groups,DC=test,DC=test,DC=test, CN=Adobe Acrobat X P
rofessional 10,OU=test All Software Groups,DC=test,DC=test,D
C=co.uk, CN=Silverlight_Microsoft_4.0.60.0_LCL,OU=test
All Software Groups,DC=test,DC=test,DC=test}
Name : %hostname ObjectClass : computer
ObjectGUID : 5cf00026-c91a-422e-8a3e-7ee546456717f
SamAccountName : Test
SID : f-1-5-21-18934363546-5655752-5353453-564535
UserPrincipalName :
有沒有一種方法,我可以只具有的memberOf返回(連接到本機AD agroups的列表,並與剛剛listsed組名稱列表排序,例如只需:
Silverlight_Microsoft_4.0.60.0_LCL
Adobe Acrobat XP Professional
等
謝謝,工作。你能幫我解決這個問題嗎?我試圖獲取輸出的組名,並將它們放到DataGridView窗體中,但我一直得到的是輸出到DatagridView的數字。函數Get-AD {$ active_d =(Get-ADComputer -Identity $ current_hostname.text -Property MemberOf).MemberOf -replace'^ CN =([^,] +),OU =。+ $','$ 1'$ array =新對象System.Collections.ArrayList $ array.AddRange($ active_d)$ current_output.DataSource = $ array $ current_output.refresh()}我現在正在使用上述但它不工作 – obious 2012-04-24 09:51:53
此外,你可以簡要解釋 - 替換'^ CN =([^,] +),OU =。+ $','$ 1' please? – obious 2012-04-24 10:21:29
正則表達式捕獲CN =和下一個逗號之間的任何內容,([^,] +)表示任何不是逗號的字符。捕獲正在取代整個字符串。 – 2012-04-24 11:51:01