Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. Add-Type -Path (Get-Command 'Microsoft.SqlServer.Management.UserSettings.dll').Source
  2. [bool]$loaded = $false
  3. Get-Item -Path 'C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.ConnectionInfo\*\Microsoft.SqlServer.ConnectionInfo.dll' | Select-Object -ExpandProperty FullName | Sort-Object -Descending | ForEach-Object {if (!$loaded ){try {Add-Type -Path $_;Write-Verbose "Successfully loaded $_";$loaded=$true}catch{Write-Warning "Failed to load $_"}}}
  4.  
  5. [string]$settingsFilePath = (Resolve-Path (Join-Path -Path $env:APPDATA -ChildPath 'Microsoft/SQL Server Management Studio/*/SqlStudio.bin')).Path | Sort-Object -Descending | Select-Object -First 1
  6. if ($settingsFilePath) {
  7. try {
  8. [System.IO.MemoryStream]$ms = [System.IO.File]::ReadAllBytes($settingsFilePath)
  9. [System.Runtime.Serialization.Formatters.Binary.BinaryFormatter]$formatter = New-Object -TypeName 'System.Runtime.Serialization.Formatters.Binary.BinaryFormatter'
  10. [Microsoft.SqlServer.Management.UserSettings.SqlStudio]$sqlStudio = $formatter.Deserialize($ms) #[Microsoft.SqlServer.Management.UserSettings.SettingsDictionary[[System.Guid],[Microsoft.SqlServer.Management.UserSettings.ServerTypeItem]]]
  11. foreach ($serverTypeItem in $sqlStudio.SSMS.ConnectionOptions.ServerTypes.Values) { #[Microsoft.SqlServer.Management.UserSettings.ServerTypeItem]
  12. foreach ($server in $serverTypeItem.Servers) { # [Microsoft.SqlServer.Management.UserSettings.ServerConnectionItem]
  13. ([PSCustomObject][Ordered]@{
  14. Instance = $server.Instance
  15. AuthMeth = ([Microsoft.SqlServer.Management.Common.SqlConnectionInfo+AuthenticationMethod]$server.AuthenticationMethod)
  16. Connections = $server.Connections
  17. })
  18.  
  19. }
  20. }
  21. } finally {
  22. $ms.Dispose()
  23. }
  24. } else {
  25. throw 'Could not find SqlStudio.bin. Older versions used MRU.dat... but I''ve not coded a solution for that, sorry!'
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement