2015-02-23 52 views
0

因此,我正在嘗試在AD中查詢一個組,然後使用該列表創建電子郵件地址列表。我正在使用下面的命令:無法從安全組成員獲取電子郵件列表

Get-ADGroupMember mygroup -Server my.server.com | Select-Object SID | Get-ADUser -Identity $_.SID -Properties cn,mail -server my.server.com | Select-Object Samaccountname,mail | Format-Table Samaccountname,mail 

當我運行此我得到下面的錯誤。

Get-ADUser:無法驗證參數'Identity'上的參數。參數爲null或參數集合的元素包含空值。

在行:1字符:107

  • ...用戶-Identity $ _ SID -Properties CN,郵件-server na.ko.com |。選擇-對象薩瑪...

    • CategoryInfo:InvalidData:(:) [獲取-ADUser便有],ParameterBindingValidationException
    • FullyQualifiedErrorId:ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser

任何人都覺得自己喜歡教新生嗎?

+0

你應該能夠跳過這兩者你選擇的命令,和你需要用你的Get-ADUser命令在'ForEach {Get-ADUser ....}' – TheMadTechnician 2015-02-23 23:00:40

+0

謝謝@TheMadTechnician。我知道這很簡單。愚蠢的ForEach-s。 – Chris 2015-02-23 23:05:32

+0

@TheMadTechnician你應該發佈這個答案,所以我可以選擇它。 – Chris 2015-02-23 23:13:54

回答

0

,使其成爲一個答案,你可以跳過Select語句,並通過一個foreach循環運行Get-ADUser便有:

Get-ADGroupMember mygroup -Server my.server.com | ForEach{ Get-ADUser -Identity $_.SID -Properties cn,mail -server my.server.com | Format-Table Samaccountname,mail