我想组合下面的脚本,以便它可以自动复制 AD 数据库内容,而无需等待 15 分钟,仅适用于所有在线域控制器。
function Replicate-AllDomainController
{
(Get-ADDomainController -Filter *).Name | Foreach-Object { repadmin /syncall $_ (Get-ADDomain).DistinguishedName /e /A | Out-Null }; Start-Sleep 10; Get-ADReplicationPartnerMetadata -Target "$env:userdnsdomain" -Scope Domain | Select-Object Server, LastReplicationSuccess
}
function Test-AllDomainController
{
$dcs = (Get-ADDomainController -Filter *).Name
foreach ($items in $dcs)
{
Test-Connection $items -Count 1
}
}
Try
{
Where-Object (Test-AllDomainController)
{
Replicate-AllDomainController
}
}
Catch
{
Write-Output "Exception Type: $($_.Exception.GetType().FullName)"
Write-Output "Exception Message: $($_.Exception.Message)"
}
如何正确执行,以便在成功复制最后一个 AD DC 后停止,没有问题?如果有问题,请在单独的 Out-GridView 中显示有问题的 AD 域控制器。