A function that will return the AD site the local computer is currently connected to. Useful for PowerShell login scripts that need to target specific sites.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Get-ComputerADSite() | |
{ | |
<# | |
.Synopsis | |
Get the computers current AD site from the computer Netlogon information. | |
.Example | |
Get-ComputerADSite | |
.Notes | |
Author: David Green | |
#> | |
[CmdletBinding()] | |
param() | |
Write-Verbose 'Getting the computers current AD site from HKLM:\SYSTEM\CurrentControlSet\services\Netlogon\Parameters.' | |
[string]$adsite = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\services\Netlogon\Parameters' -name DynamicSiteName).DynamicSiteName | |
#Trim the last 2 characters from the site as this registry value seems to have " R" appended. | |
$adsite.Substring(0, ($adsite.Length -2)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment