powershell - Search GC replicas and find AD account -
i have issue ad replication. use 3rd party app create accounts in ad , powershell script (called app) create exchange accounts. in 3rd party app can not tell gc ad account has been created on , therefore have wait 20 minutes replication happen.
what trying find gc account has been created on or replicated , connect server using....
set-adserversettings -preferredserver $adserver
i have below script , can't work out stop when finds account , assign gc $adserver variable. write-host line there testing.
$forestinfo = [system.directoryservices.activedirectory.forest]::getcurrentforest() $gcs = $forestinfo.findallglobalcatalogs() import-module activedirectory foreach ($gc in $gcs) { write-host $gc.name get-aduser $aduser }
tia
andy
you can check whether get-aduser
returns more 0 objects determine whether gc satisfied query. after that, use set-adserversettings -preferredglobalcatalog
configure preference
you need specify want search global catalog , not local directory. global catalog accessible port 3268 on dc, becomes like:
$forestinfo = [system.directoryservices.activedirectory.forest]::getcurrentforest() $gcs = $forestinfo.findallglobalcatalogs() import-module activedirectory $adusername = "someusername" $addomaindn = "dc=child,dc=domain,dc=tld" $finalglobalcatalog = $null foreach ($gc in $gcs) { $gcendpoint = "{0}:3268" -f $gc.name $searchresult = get-aduser -ldapfilter "(&(samaccountname=$adusername))" -server $gcendpoint -searchbase $addomaindn -erroraction silentlycontinue if(@($searchresult).count -gt 0){ $finalglobalcatalog = $gc break } } if($finalglobalcatalog){ write-host "found one: $($finalglobalcatalog.name)" set-adserversettings -preferredglobalcatalog $finalglobalcatalog.name } else { write-host "unable locate gc replica containing user $adusername" }
Comments
Post a Comment