PowerShell:重命名AD对象后,Move-Mailbox无法找到对象

时间:2012-12-07 18:07:21

标签: powershell exchange-server

因此,在我的脚本中,当用户更改其名称时,我相应地重命名其AD对象,更改其Exchange(2007)属性,然后根据这些更改,我更改它所在的信息存储。

我在检索邮箱时将新的DistinguishedName存储在$ newDN中,显式尝试使用DC01.domain.local,然后当我尝试移动时,它尝试搜索DC02.domain.local,因此找不到对象由于复制滞后而在下面收到此错误。任何人对此都有任何想法?非常感谢!

StatusCode:-1056749240 StatusMessage:步骤中发生错误:批准对象。无法打开对象'LDAP://DC02.domain.local/CN=di matteo \,robert,OU = Users,DC = domain,DC = local',但有错误:服务器上没有此类对象。

$mailbox = Get-Mailbox -ID $newDN `
    -DomainController DC01.domain.local

$mailbox | Move-Mailbox `
    -TargetDatabase $targetIS `
    -Confirm:$False `
    -DomainController DC01.domain.local `
    -GlobalCatalog DC01.domain.local

有时移动有效,但是当它没有时,它会将SourceDomainController属性保留为空(如下所示),就好像它确实有效一样,它会使用DC01.domain.local正确填充它。

SourceServer                     : CCR.domain.local
SourceDatabase                   : CCR\IS1\IS1
SourceGlobalCatalog              : DC01.domain.local
SourceDomainController           : 
TargetGlobalCatalog              : DC01.domain.local
TargetDomainController           : DC01.domain.local
TargetMailbox                    : 
TargetServer                     : CCR.domain.local
TargetDatabase                   : CCR\IS2\IS2

束手无策。

1 个答案:

答案 0 :(得分:0)

好吧,我不知道为什么我得到了我的结果,但是我的解决方法就在这里......就像我之前说过的那样,我查询/写入我所有的AD更改为'DC01.domain.local '但现在,当我调用我的函数时,我在'DC02.domain.local'上进行邮箱查询。如果查找失败,请递增计数器,休眠约20秒,然后重试。我的初步测试,它只需要循环一次。

$dc = "DC01.domain.local"

Function moveDB ($targetIS, $newDN, $counter) {

$dn = (Get-Mailbox -ID $newDN -DomainController $dc).DistinguishedName

If (!(Get-Mailbox $dn -DomainController "DC02.domain.local")) {
    $counter++
    If ($counter -le 4) {
        Write-Host "`nPlease wait while I search for the mailbox object...`n"  -ForegroundColor Yellow -BackgroundColor Red
        Start-Sleep -Seconds 20
        moveDB $targetIS $dn $dbCounter
    }
    Else {
        Write-Host "Mailbox was not moved!  Please move manually to $targetIS..."  -ForegroundColor Yellow -BackgroundColor Red
        return
    }
}
Else {
    $dn | Move-Mailbox `
        -DomainController $dc `
        -GlobalCatalog $dc `
        -TargetDatabase $targetIS `
        -Confirm:$False
    }
}
相关问题