Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-DbaRegistered Server - Add Source #5606

Merged
merged 1 commit into from
May 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions functions/Get-DbaRegServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ function Get-DbaRegServer {
)
begin {
if ($ResolveNetworkName) {
$defaults = 'ComputerName', 'FQDN', 'IPAddress', 'Name', 'ServerName', 'Group', 'Description'
$defaults = 'ComputerName', 'FQDN', 'IPAddress', 'Name', 'ServerName', 'Group', 'Description', 'Source'
}
$defaults = 'Name', 'ServerName', 'Group', 'Description'
$defaults = 'Name', 'ServerName', 'Group', 'Description', 'Source'
# thank you forever https://social.msdn.microsoft.com/Forums/sqlserver/en-US/57811d43-a2b9-4179-a97b-a9936ddb188e/how-to-retrieve-a-password-saved-by-sql-server?forum=sqltools
function Unprotect-String([string] $base64String) {
return [System.Text.Encoding]::Unicode.GetString([System.Security.Cryptography.ProtectedData]::Unprotect([System.Convert]::FromBase64String($base64String), $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser))
Expand Down Expand Up @@ -145,7 +145,9 @@ function Get-DbaRegServer {
$initMethod = $class.GetMethod('InitChildObjects', [Reflection.BindingFlags]'Static,NonPublic')
$store = ($initMethod.Invoke($null, @($file)))
# Local Reg Servers
$servers += $store.DatabaseEngineServerGroup.GetDescendantRegisteredServers()
foreach ($tempserver in $store.DatabaseEngineServerGroup.GetDescendantRegisteredServers()) {
$servers += $tempserver | Add-Member -Force -Name Source -Value "Local Server Groups" -MemberType NoteProperty -PassThru
}
# Azure Reg Servers
$azureids = @()
if ($store.AzureDataStudioConnectionStore.Groups) {
Expand Down Expand Up @@ -173,6 +175,7 @@ function Get-DbaRegServer {
$tempserver.ConnectionString = $adsconn.ConnectionString
}
# update read-only or problematic properties
$tempserver | Add-Member -Force -Name Source -Value "Azure Data Studio" -MemberType NoteProperty
$tempserver | Add-Member -Force -Name ServerName -Value $server.Options['server'] -MemberType NoteProperty
$tempserver | Add-Member -Force -Name Id -Value $server.Id -MemberType NoteProperty
$tempserver | Add-Member -Force -Name CredentialPersistenceType -Value 1 -MemberType NoteProperty
Expand Down Expand Up @@ -231,6 +234,10 @@ function Get-DbaRegServer {
Add-Member -Force -InputObject $server -MemberType NoteProperty -Name SecureConnectionString -Value (ConvertTo-SecureString -String $connstring -AsPlainText -Force)
}
}

if (-not $server.Source) {
Add-Member -Force -InputObject $server -MemberType NoteProperty -Name Source -value "Central Management Servers"
}
Add-Member -Force -InputObject $server -MemberType NoteProperty -Name ComputerName -value $serverstore.ComputerName
Add-Member -Force -InputObject $server -MemberType NoteProperty -Name InstanceName -value $serverstore.InstanceName
Add-Member -Force -InputObject $server -MemberType NoteProperty -Name SqlInstance -value $serverstore.SqlInstance
Expand Down