简体   繁体   English

我如何为 powershell 的每个联系人提取邮件联系人组?

[英]How can I pull Mail Contact groups for each contact with powershell?

I am trying to create a script to pull contact groups and put them in an excel sheet.我正在尝试创建一个脚本来提取联系人组并将它们放入 excel 表中。 Here is what I have so far:这是我到目前为止所拥有的:

Import-Module ActiveDirectory
Get-ADUser -SearchBase "OU=XXXXX,OU=XXXXX,DC=XXXXXX,DC=DOM" -Filter * | foreach-object                                   {
write-host "User:" $_.Name -foreground green
Get-ADPrincipalGroupMembership $_.SamAccountName | foreach-object {
    write-host "Member Of:" $_.name
}
} | Export-Csv c:\tech.csv

This works for User accounts (except for the export for some reason), but not Contacts.这适用于用户帐户(出于某种原因导出除外),但不适用于联系人。

The script doesn't return anything for the distro groups of contacts when running it.该脚本在运行时不会为联系人的发行版组返回任何内容。 We have a list of contacts that are part of distro groups that we, most likely, don't need anymore.我们有一份联系人列表,这些联系人属于我们很可能不再需要的发行版组。 I'm running this from a remote computer through powershell and I figured I could use this script and point it to the specific Contact OU.我通过 powershell 从远程计算机运行它,我想我可以使用这个脚本并将它指向特定的联系人 OU。

I have also tried this from our Exchange servers:我也在我们的 Exchange 服务器上试过这个:

Get-Contact | 
sort-object LastName | 
%{ Get-MailContact $_.DistinguishedName | select Name,Member,PrimarySMTPAddress } 

There doesn't appear to be a "Members" property.似乎没有“成员”属性。

try this.尝试这个。 Not optimal, but it works.不是最优的,但它有效。

get-distributiongroup |获取分发组 | foreach {write-host ---------- $ .samaccountname; foreach {写主机 ---------- $ .samaccountname; get-distributiongroupmember -resultsize unlimited $ .samaccountname | get-distributiongroupmember -resultsize 无限 $ .samaccountname | where {$_.RecipientType -eq "mailcontact"} |其中 {$_.RecipientType -eq "mailcontact"} | ft name}英尺名称}

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

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