导出安全组中所有用户的电子邮件地址 [英] Exporting email address of all users in Security Group

查看:54
本文介绍了导出安全组中所有用户的电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一些可以获取活动目录安全组中所有用户的电子邮件地址的脚本.

到目前为止我所拥有的:

$Groups = Get-ADGroup -filter {Name -like "VIPEmail" } |选择对象名称ForEach($Groups 中的 $Group){Get-ADGroupMember -identity $($group.name) -recursive |选择对象 smaccountname}

显然这只会返回 samaccountname,它确实如此.我用 EmailAddress 替换了 samaccountname,但它什么也没做.

解决方案

为了保持原始格式,以便您可以看到哪里出错了:

$Groups = Get-ADGroup -filter {Name -like "09-Admins" } |选择对象名称ForEach($Groups 中的 $Group){Get-ADGroupMember -identity $($group.name) -recursive |Get-ADUser -Properties 邮件 |选择对象邮件}

问题是您正在尝试读取 Get-ADGroupMember 返回类型没有的属性 (Microsoft.ActiveDirectory.Management.ADPrincipal).您需要将返回值通过管道传输到 Get-ADuser 并指定您希望它提取 emailaddress 属性.默认情况下,Get-ADUser 不会拉取用户的大部分属性,因此您需要指定要检索的任何其他属性(或者只是使用-Properties *"选择所有属性,但这有点草率).

Mjolinor 击败了我的答案,但我认为值得详细说明他的回应.

I'm trying to script something where I can get the email address of all users in an active directory security group.

What I have so far:

$Groups = Get-ADGroup -filter {Name -like "VIPEmail" } | Select-Object Name
ForEach ($Group in $Groups) {
  Get-ADGroupMember -identity $($group.name) -recursive | Select-Object samaccountname
}

Obviously this will only return the samaccountname, which it does. I replace samaccountname with EmailAddress, and it does nothing.

解决方案

To keep with your original formatting so you can see where you went wrong:

$Groups = Get-ADGroup -filter {Name -like "09-Admins" } | Select-Object Name
ForEach ($Group in $Groups) {
   Get-ADGroupMember -identity $($group.name) -recursive | Get-ADUser -Properties mail | Select-Object mail
}

The problem is that you are trying to read a property that the Get-ADGroupMember return type doesn't have (Microsoft.ActiveDirectory.Management.ADPrincipal). You need to pipe that return into Get-ADuser AND specify that you want it to pull the emailaddress property. Get-ADUser will not pull most properties of a user by default, so you need to specify any additional properties you would like to retrieve (or just select all of them with "-Properties *", but that's kind of sloppy).

Mjolinor beat me to the answer, but I figured it was worth elaborating a little on his response.

这篇关于导出安全组中所有用户的电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆