Skip to content

Commit

Permalink
Get-DbaRegisteredServer - add default configuration for CMS and Inclu…
Browse files Browse the repository at this point in the history
…deLocal (#5607)

* Add Source

* add configs for cms
  • Loading branch information
potatoqualitee authored May 26, 2019
1 parent a05a0ad commit 8137f54
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
17 changes: 12 additions & 5 deletions functions/Get-DbaRegServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function Get-DbaRegServer {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
param (
[parameter(ValueFromPipeline)]
[DbaInstanceParameter[]]$SqlInstance,
[DbaInstanceParameter[]]$SqlInstance = (Get-DbatoolsConfigValue -FullName 'commands.get-dbaregserver.defaultcms'),
[PSCredential]$SqlCredential,
[string[]]$Name,
[string[]]$ServerName,
Expand All @@ -100,14 +100,14 @@ function Get-DbaRegServer {
[int[]]$Id,
[switch]$IncludeSelf,
[switch]$ResolveNetworkName,
[switch]$IncludeLocal,
[switch]$IncludeLocal = (Get-DbatoolsConfigValue -FullName 'commands.get-dbaregserver.includelocal'),
[switch]$EnableException
)
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
6 changes: 5 additions & 1 deletion internal/configurations/settings/commands.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ Set-DbatoolsConfig -FullName 'commands.Write-DbaDbTableData.ignorenull' -Value $
Set-DbatoolsConfig -FullName 'commands.Write-DbaDbTableData.raw' -Value $false -Initialize -Validation bool -Description "When passing random objects at Write-DbaDbTableData, it will convert them to a DataTable before writing it, using ConvertTo-DbaDataTable. This setting controls whether all properties will be stored as string (`$true) or as much as possible in their native type (`$false)"

# Resolve-DbaNetworkName
Set-DbatoolsConfig -FullName 'commands.resolve-dbanetworkname.bypass' -Value $false -Initialize -Validation bool -Description "Use input exactly as stated instead of attempting to resolve"
Set-DbatoolsConfig -FullName 'commands.resolve-dbanetworkname.bypass' -Value $false -Initialize -Validation bool -Description "Use input exactly as stated instead of attempting to resolve"

# Get-DbaRegServer
Set-DbatoolsConfig -FullName 'commands.get-dbaregserver.defaultcms' -Value $null -Initialize -Validation string -Description "Use a default Central Management Server"
Set-DbatoolsConfig -FullName 'commands.get-dbaregserver.includelocal' -Value $false -Initialize -Validation bool -Description "Include local servers by default"

0 comments on commit 8137f54

Please sign in to comment.