在 PowerShell 中获取当前 Active Directory (AD) 站点有哪些不同方法 - 哪种方法最快、最高效且适用于大多数场景?
有多种方法可用:
(& "$env:SystemRoot\System32\nltest.exe" /DSGETSITE)[0]
[System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::GetComputerSite().Name
(Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters).DynamicSiteName
(Get-CimInstance -ClassName Win32_NTDomain -Filter 'DomainName != NULL').ClientSiteName
[System.__ComObject].InvokeMember("SiteName", [System.Reflection.BindingFlags]::GetProperty, $null, (New-Object -ComObject "ADSystemInfo"), $null)
选项 1-3:https://powershellmagazine.com/2013/04/23/pstip-get-the-ad-site-name-of-a-computer/
选项 4:https://www.reddit.com/r/PowerShell/comments/4cjdk8/get_the_ad_site_name_of_a_computer/
选项 5:https://learn.microsoft.com/en-us/windows/win32/adsi/iadsadsysteminfo-property-methods