Created
January 28, 2025 15:19
-
-
Save Mayyhem/741ae9c97a92d36131a76156760e0553 to your computer and use it in GitHub Desktop.
Get-SiteServerRegData
This file contains hidden or 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-SiteServerRegData { | |
| [CmdletBinding()] | |
| param( | |
| [Parameter(Mandatory=$true)] | |
| [string]$ComputerName | |
| ) | |
| # Access the remote registry | |
| $RegPath = "SOFTWARE\Microsoft\SMS" | |
| $SubKey = "Triggers" | |
| try { | |
| # Connect to the remote registry's LocalMachine hive | |
| $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $ComputerName) | |
| $subKeyPath = "$RegPath\$SubKey" | |
| # Open the target subkey | |
| $key = $reg.OpenSubKey($subKeyPath) | |
| if ($key) { | |
| # Print all subkeys (if any) | |
| $subKeyNames = $key.GetSubKeyNames() | |
| if ($subKeyNames.Count -eq 1) { | |
| Write-Output "Site code:" | |
| foreach ($subKeyName in $subKeyNames) { | |
| Write-Output " $subKeyName" | |
| } | |
| } | |
| elseif ($subKeyNames.Count -eq 0) { | |
| Write-Output "No subkeys found under this key." | |
| } | |
| else { | |
| Write-Output "This is weird. There are more than one site codes here:" | |
| foreach ($subKeyName in $subKeyNames) { | |
| Write-Output " $subKeyName" | |
| } | |
| } | |
| # Close the key | |
| $key.Close() | |
| } | |
| else { | |
| Write-Output "Registry key '$SubKey' does not exist on ${ComputerName}." | |
| } | |
| # Close the registry connection | |
| $reg.Close() | |
| } | |
| catch { | |
| Write-Output "Failed to access registry on ${ComputerName}. Error: $_" | |
| } | |
| # Define the registry path and subkey | |
| $RegPath = "SOFTWARE\Microsoft\SMS\COMPONENTS\SMS_SITE_COMPONENT_MANAGER" | |
| $SubKey = "Multisite Component Servers" | |
| try { | |
| # Connect to the remote registry's LocalMachine hive | |
| $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $ComputerName) | |
| $subKeyPath = "$RegPath\$SubKey" | |
| # Open the target subkey | |
| $key = $reg.OpenSubKey($subKeyPath) | |
| if ($key) { | |
| # Print all subkeys (if any) | |
| $subKeyNames = $key.GetSubKeyNames() | |
| if ($subKeyNames.Count -eq 0) { | |
| Write-Output "Site database is local to the site server" | |
| } | |
| elseif ($subKeyNames.Count -eq 1) { | |
| Write-Output "Site database server:" | |
| foreach ($subKeyName in $subKeyNames) { | |
| Write-Output " $subKeyName" | |
| } | |
| } | |
| else { | |
| Write-Output "Site database servers:" | |
| foreach ($subKeyName in $subKeyNames) { | |
| Write-Output " $subKeyName" | |
| } | |
| } | |
| # Close the key | |
| $key.Close() | |
| } | |
| else { | |
| Write-Output "Registry key '$SubKey' does not exist on ${ComputerName}." | |
| } | |
| # Close the registry connection | |
| $reg.Close() | |
| } | |
| catch { | |
| Write-Output "Failed to access registry on ${ComputerName}. Error: $_" | |
| } | |
| $SubKey = "Component Servers" | |
| try { | |
| # Connect to the remote registry's LocalMachine hive | |
| $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $ComputerName) | |
| $subKeyPath = "$RegPath\$SubKey" | |
| # Open the target subkey | |
| $key = $reg.OpenSubKey($subKeyPath) | |
| if ($key) { | |
| # Print all subkeys (if any) | |
| $subKeyNames = $key.GetSubKeyNames() | |
| if ($subKeyNames.Count -gt 0) { | |
| Write-Output "Site system roles:" | |
| foreach ($subKeyName in $subKeyNames) { | |
| Write-Output " $subKeyName" | |
| } | |
| } | |
| else { | |
| Write-Output "No subkeys found under this key." | |
| } | |
| # Close the key | |
| $key.Close() | |
| } | |
| else { | |
| Write-Output "Registry key '$SubKey' does not exist on ${ComputerName}." | |
| } | |
| # Close the registry connection | |
| $reg.Close() | |
| } | |
| catch { | |
| Write-Output "Failed to access registry on ${ComputerName}. Error: $_" | |
| } | |
| Write-Host | |
| } | |
| # Example Usage | |
| Get-SiteServerRegData -ComputerName cas-pss | |
| Get-SiteServerRegData -ComputerName ps1-pss | |
| Get-SiteServerRegData -ComputerName ps1-psv | |
| Get-SiteServerRegData -ComputerName ps2-pss |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment