创build有效的启用邮件的联系人,而不使用Exchange特定的cmdlet

我已经写了一个powershell脚本来定期处理并将大量(超过70k)的联系人导入到Exchange环境中。 脚本工作正常,但我想尽可能加快速度。 用于导入和导出数据的最耗时的部分。

通过删除Exchange 2013 cmdlet上的大部分依赖关系,我能够缩短大量处理时间。 例如,使用“本机”Get-ADObject cmdlet来提取数据,而不是Exchange特定的Get-MailContact和Get-Contact的组合,我能够将处理时间缩短10倍。

该命令如下所示:

$result = Get-ADObject -LDAPFilter "(objectClass=contact)" -searchBase "$OU" -ResultPageSize 100 -property GivenName, SN, DisplayName, Department, physicalDeliveryOfficeName , telephoneNumber, mailnickname, targetaddress | select @{ label="Email"; Expression={ ($_.targetaddress -replace "^SMTP:","").tostring().Tolower().Trim() }}, @{ N="Alias"; E={ $_.mailnickname} }, @{ N="FirstName"; E={ $_.GivenName} }, @{ N="LastName"; E={ $_.SN} }, DisplayName, @{ N="Office"; E={ $_.physicalDeliveryOfficeName} } , Department, @{ N="Phone"; E={ $_.telephoneNumber} } 

现在我想能够做到相反,创造联系。 也就是说,创build一个启用邮件的联系人,而不使用Exchange特定的cmdlet。 我设法使用这个命令创build一个联系人:

 $Attributes = @{'displayName' = $displayname; 'GivenName' = $first; 'SN' = $last; 'Department' = $department; 'physicalDeliveryOfficeName' = $office; 'telephoneNumber' = $phone; 'mail' = $email; 'mailnickname' = $alias; 'targetaddress' = $email} New-AdObject -Type Contact -Name $displayname -Path $OU -OtherAttributes $Attributes -whatif 

但是,虽然该对象显然是正确创build的,但它并不显示在Exchange上的联系人中。 到目前为止,我已经能够实现这一目标的唯一方法是在创build后在对象上运行“Enable-MailContact”cmdlet,这违背了在进程中不使用Exchange cmdlet的目的。

所以我的问题是,是否有人知道是否有一种方法来创build一个function的邮件使能的联系人,只使用New-ADObject cmdlet,而不依赖于Exchange特定的cmdlet?

谢谢。

我的猜测会是缺lessproxyAddresses属性。 您可以检查AD用户和计算机以查看由Enable-MailContact属性添加的属性。

事实certificate,重要的缺失项目是“showinaddressbook”财产。

本文介绍它是如何工作的: https : //support.microsoft.com/en-us/kb/253828

showInAddressBook属性有两个目的。 首先是让人们通过消息应用程序编程接口(MAPI)客户端(如Microsoft Outlook)查看地址列表中列出的条目。 第二个目的是允许用户在MAPI客户端上“parsing名称”。

尽pipe文章引用了自Exchange 2007以来不存在的收件人更新服务(RUS),但我认为启用对象的邮件的底层过程仍然是相同的。

所以基本上要创build一个启用邮件的联系人,而不使用Exchange 2013 cmdlet,我做了这样的事情:

 $alias = "ADDR-00001" $email = "[email protected]" $first = "Joe" $last = "Doe" $displayname = "DOE Joe" $department = "My Dept." $office = "My Office" $phone = "55554448934" $proxyAddresses = "SMTP:[email protected]" $DestinationOU = "OU=contact,OU=example,DC=corp,DC=example,DC=com" $AddressBook = "CN=Default Global Address List,CN=All Global Address Lists,CN=Address Lists Container,CN=Example-Org,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=corp,DC=example,DC=com","CN=All Contacts,CN=All Address Lists,CN=Address Lists Container,CN=Example-Org,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=corp,DC=example,DC=com" $Attributes = @{'displayName' = $displayname; 'GivenName' = $first; 'SN' = $last; 'Department' = $department; 'physicalDeliveryOfficeName' = $office; 'telephoneNumber' = $phone; 'mail' = $email; 'mailnickname' = $alias; 'targetaddress' = $email; 'proxyAddresses' = $proxyAddresses; 'showinaddressbook' = $AddressBook;} New-AdObject -Type Contact -Name $displayname -Path $DestinationOU -OtherAttributes $Attributes 

生成的对象仍然没有LegacyExchangeDN值,它有一个特殊的ExchangeVersionAddressListMembership属性现在已填充。

 Get-Mailcontact "[email protected]" | select displayName, RecipientType, LegacyExchangeDN, ExchangeVersion, AddressListMembership| fl DisplayName : DOE Joe RecipientType : MailContact LegacyExchangeDN : ExchangeVersion : 0.0 (6.5.6500.0) AddressListMembership : {\All Contacts, \Default Global Address List}