无法从安全组的成员处获取电子邮件列表

时间:2015-02-23 22:56:17

标签: powershell active-directory

所以我试图在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,mail -server na.ko.com | Select-Object Sama ...

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

有人想教新手吗?

1 个答案:

答案 0 :(得分: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