Принудительная репликация для всех контроллеров домена AD - PullRequest
0 голосов
/ 03 августа 2020

Я пытаюсь исправить проблему с помощью приведенного ниже сценария Powershell для принудительной репликации AD из одного AD для всех его партнеров по репликации.

Цель сценария - иметь возможность запускать его с рабочей станции без установлен AD PowerShell или RSAT.

$forest = [System.DirectoryServices.ActiveDirectory.forest]::getcurrentforest()
$Domains = $forest.domains

Foreach ($Domain in $domains) {
    $dcs = $Domain.FindAllDomainControllers()
    write-host $($Domain.name)

    foreach ($dc in $dcs) {
        $pingtest = $(Test-Connection $($dc.name) -Quiet -Count 2)
        $DCIP = [System.Net.Dns]::GetHostAddresses($dc.name)
        $HostnameByIP = [System.Net.Dns]::GetHostbyAddress($dc.Name.ToString())
        write-host "DC Hostname: $($HostnameByIP) - $($DCIP) up : $pingtest"
        
        #only get replication info if server is up
        if ($pingtest) {
            #get all replication infomation
            $repNeighbors = $dc.GetAllReplicationNeighbors()
            foreach ($rep in $repNeighbors) {
                #if the last replication result is -gt 0 it is an error
                if ($rep.LastSyncResult -gt 0) {
                    #add code here to react to an error
                    write-host "$($rep.SourceServer) to $($dc.name) replication error"
                }
                else {
                    # If no issue on the AD replication, 
                    # then force the synch from where the current AD RDP session is running, 
                    # so it is replicating to all AD domain controllers, without waiting for 15 minutes.
                    #
                    # Calculate the KCC to determine whatchanges is made on the current AD domain controller:
                    repadmin /kcc $_.Name
                    # Replicate from the current AD domain controller where the changes has been made:
                    # repadmin /syncall /A(ll partitions) P(ush) e(nterprise, cross sites) d(istinguished names) parameters $dc.Name
                    repadmin /syncall $dc.Name /APed
                    #
                }
            }
        }
    }
}

Я получаю следующую ошибку:

Exception calling "GetHostByAddress" with "1" argument(s): "An invalid IP address was specified."
At line:11 char:9
+         $HostnameByIP = [System.Net.Dns]::GetHostbyAddress($dc.Name.T ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FormatException
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...