Run Error
brentgeren opened this issue · 1 comments
I am getting an error when attempting to run the script on a multi-domain forest.
This is what it's returning:
You cannot call a method on a null-valued expression.
At D:\XXXX\XXXXX.ps1:49 char:1
- $source_dc_fqdn = ($dcname.Name).tolower()
-
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
I think myself and a colleague may have figured it out.
This is where we made our edits and now it's working.
Original:
38 $myForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
39 $dclist = $myforest.Sites | % { $_.Servers }
49 $source_dc_fqdn = ($dcname.Name).tolower()
Modified:
38 # removed this line
38 $dclist = [system.directoryservices.activedirectory.Forest]::GetCurrentForest().domains | %{$_.DomainControllers.name}
48 $source_dc_fqdn = ($dcname).tolower()
After those slight modifications, the script works perfectly as intended. We found where sometimes the entire list of DCs in a forest aren't pulled properly with the original commands.
Hope this helps.