简体   繁体   English

如何使用 dsquery 列出通讯组列表的成员?

[英]How to use dsquery to list the members of a distribution list?

I have this command to find a distribution list object我有这个命令来查找分发列表 object

dsquery * -filter "(&(cn=*group))"

but now how can I find the users from that, I want to loop through and get their names and email addresses from it.但现在我如何从中找到用户,我想循环并从中获取他们的姓名和 email 地址。

Thanks谢谢

Now that you have the group name, you can use PowerShell to iterate through the group and extract the information you need:现在您有了组名,您可以使用 PowerShell 遍历组并提取您需要的信息:

Import-Module ActiveDirectory
$group = read-host "Please Enter Group Name: "

$members = Get-ADGroupMember -Identity $group -Recursive
    ForEach ($member in $members) {
        $memberType = $member.objectClass
           If ($memberType -eq 'user') {
           Get-ADUser -Filter "name -like '*$member'" -Properties cn,mail | Out-File c:\temp\Group_Members.csv -append
            }
        }

The code above will prompt for the group name and export the list of members, including where there is a nested group into the a file called Group_Members.csv in c:\temp.上面的代码将提示输入组名并导出成员列表,包括嵌套组的位置到 c:\temp 中名为 Group_Members.csv 的文件中。

You will need to ensure that:您需要确保:

  • Script execution is enabled in Powershell;在 Powershell 中启用脚本执行;
  • That RSAT is installed on the device that the script is executed from;该 RSAT 安装在执行脚本的设备上;
  • That the script is executed with administrator privileges.该脚本以管理员权限执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM