Last active
May 29, 2021 22:27
-
-
Save kewalaka/5a12be5c8d67a358a2fa0a89fb2fa8a1 to your computer and use it in GitHub Desktop.
This will write out the SQL aliases on the local machine in a human readable form
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
| $aliasRegistryPath = 'HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo' | |
| (Get-Item $aliasRegistryPath).Property | ForEach-Object { | |
| $aliasName = $_ | |
| $aliasTarget = Get-ItemPropertyValue $aliasRegistryPath -Name $aliasName | |
| $aliasTargetType = switch ($aliasTarget.split(',')[0]) | |
| { | |
| 'DBNMPNTW' {'a named pipe'} | |
| 'DBMSSOCN' {'a tcp port'} | |
| Default { ("an unknown target: '{0}'" -f $aliasTarget.split(',')[0]) } | |
| } | |
| $aliasTargetServer = $aliasTarget.split(',')[1] | |
| $aliasTargetPort = $aliasTarget.split(',')[2] | |
| if ($aliasTargetPort) | |
| { | |
| Write-Host "Alias: '$aliasName' points to '$aliasTargetServer' using $aliasTargetType via port '$aliasTargetPort'" | |
| } | |
| else | |
| { | |
| Write-Host "Alias: '$aliasName' points to '$aliasTargetServer' using $aliasTargetType" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment