Lerch Web Wiki

Random, erratic, no responsibility is taken for the correctness of this information

User Tools

Site Tools


powershell:ad:locate_my_dc

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

powershell:ad:locate_my_dc [2017/02/27 09:13]
marcus created
powershell:ad:locate_my_dc [2018/11/23 15:34] (current)
marcus
Line 22: Line 22:
     [System.DirectoryServices.ActiveDirectory.LocatorOptions]::​ForceRediscovery -bor `     [System.DirectoryServices.ActiveDirectory.LocatorOptions]::​ForceRediscovery -bor `
     [System.DirectoryServices.ActiveDirectory.LocatorOptions]::​WriteableRequired     [System.DirectoryServices.ActiveDirectory.LocatorOptions]::​WriteableRequired
 +$result = New-Object psobject | Select-Object -Property DomainController,​ClientSite
 try try
 { {
-    $Site = [System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::​GetComputerSite().ToString() +    $result.ClientSite ​= [System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::​GetComputerSite().ToString() 
-    $foundDC ​= ([System.DirectoryServices.ActiveDirectory.DomainController]::​FindOne($domain,​ $Site, $Options)).Name+    $result.DomainController ​= ([System.DirectoryServices.ActiveDirectory.DomainController]::​FindOne($domain,​ $result.ClientSite, $Options)).Name
 } }
 catch catch
 {      ​ {      ​
-    $foundDC ​= ([System.DirectoryServices.ActiveDirectory.DomainController]::​FindOne($domain,​ $Options)).Name+    $result.ClientSite = '​NoClientSite'​ 
 +    $result.DomainController ​= ([System.DirectoryServices.ActiveDirectory.DomainController]::​FindOne($domain,​ $Options)).Name
 } }
-$foundDC+$result
 } }
 </​code>​ </​code>​
powershell/ad/locate_my_dc.txt · Last modified: 2018/11/23 15:34 by marcus