New-MailContact - 错误消息:无法找到企业组织容器

时间:2018-04-18 15:39:35

标签: powershell exchange-server-2010

我正在进行跨林迁移,我编写了此脚本以便于迁移通讯组。我已经对它进行了测试,它可以在一个组中运行。该脚本会到达源域并获取LegacyExchangeDN以及该组上的所有SMTP地址。然后,它通过邮件启用使用ADMT迁移的目标域中的组,并添加其正常运行所需的Exchange属性。最后,该脚本从源域中删除该组并创建一个邮件联系人,以便仍在该组织中的用户可以在GAL中查看该组。我添加了处理作为批处理作业运行的逻辑,现在我收到了这个错误:

Error Message

我发现的Google搜索似乎都不适用于我的情况。有什么想法为什么创建联系人的功能导致此错误?

############# FUNCTIONS ###############################
function Get-ExchSessUG{
$exchSessionUG = $null
$exchSessNameUG = 'exchSessionUG'
foreach ($session in Get-PSSession) {
    if (($session.Name -eq $exchSessNameUG) -and ($session.Availability -eq "Available")) {
        $exchSessionUG = $session
    }
}
if ($exchSessionUG -eq $null) {
    $exchSessionUG = New-PSSession -ConfigurationName Microsoft.Exchange `
    -ConnectionUri http://server.domain.com/powershell -Name $exchSessNameUG
}
Import-PSSession -Session $exchSessionUG | Out-Null
return $exchSessionUG
}
function Show-CountdownTimer ($seconds, $reason){
### Number of seconds per 1% block ###
$pctSeconds = $seconds / 100
for ($i = $seconds; $i -gt 0; $i--) {
    Write-Progress -Activity $reason -Status "$i Seconds Left" `
        -PercentComplete ($i/$pctSeconds)
    Start-Sleep -Seconds 1
}
Write-Progress -Activity $reason -Completed -Status 'Done'
}
function New-MailContactUG ($contact) {  
New-MailContact -Name $contact.Name -DisplayName $contact.DisplayName -OrganizationalUnit $contact.OrganizationalUnit -ExternalEmailAddress $contact.ExternalEmailAddress -Alias $Contact.Alias -DomainController dc.domain.com
}
############# END FUNCTIONS ###########################

$DLs = Get-Content .\dl.group.names.txt
foreach($DL in $DLs){
Get-ExchSessUG
$group = Get-DistributionGroup $DL -DomainController 'dc.domain.com' 
[string]$x500 = 'X500:' + $group.LegacyExchangeDN
$addresses = $addresses = $group.EmailAddresses
###Custom Object###
$contact = New-Object -TypeName PSObject -Property(@{
    'Name'                 = $group.Alias;
    'DisplayName'          = $group.DisplayName;
    'OrganizationalUnit'   = "OU=Distribution Groups,OU=Org,OU=Contact Objects,DC=domain,DC=com";
    'ExternalEmailAddress' = [string]$group.PrimarySMTPAddress;
    'Alias'                = $group.Alias}
)
$group = $group.Name
Remove-DistributionGroup $group -DomainController 'dc.domain.com' -Confirm:$false
New-MailContactUG $contact

Enable-DistributionGroup $group -DomainController 'dc.domain2.local'
Show-CountdownTimer 20 'Waiting for the Distribution Group to replicate...'   
Set-DistributionGroup $group -EmailAddressPolicyEnabled $false -DomainController 'dc.domain2.local'
Set-DistributionGroup $group -EmailAddresses @{Add=$x500} -DomainController 'dc.domain2.local'

foreach($address in $addresses){
    $fAddress = $address.tolower()
    Set-DistributionGroup $group -emailAddresses @{Add=$fAddress} -DomainController 'dc.domain2.local' | Out-Null
}
}
Get-PSSession | Remove-PSSession

0 个答案:

没有答案