Skip to content
Permalink
Browse files

Library Update to better support Smo Server Reuse and Azure (#5204)

* initial change

* clean pdb

* undo

* try without port

* Revert "try without port"

This reverts commit 8c5bca3.

* Revert "undo"

This reverts commit 62d4592.

* Revert "clean pdb"

This reverts commit f99d84f.

* dlls broughten

* catch empty

* update tests to use new required field

* fixed issue with sending no computername

this may introduce perf issues when doing hundreds of servers

* fffuu

* fix empty string issue
  • Loading branch information...
potatoqualitee committed Mar 15, 2019
1 parent 705253c commit d21cdc254989299677edc1690c1a273bffea32fa
BIN -512 Bytes (100%) bin/dbatools.dll
Binary file not shown.
@@ -1,5 +1,5 @@
# Current library Version the module expects
$currentLibraryVersion = New-Object System.Version(0, 10, 0, 70)
$currentLibraryVersion = New-Object System.Version(0, 10, 0, 71)

<#
Library Versioning 101:
BIN -512 Bytes (100%) bin/net452/dbatools.dll
Binary file not shown.
BIN -2 KB (99%) bin/net452/dbatools.pdb
Binary file not shown.
@@ -782,7 +782,7 @@
"Microsoft.Management.Infrastructure/1.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-EhQ4sbjNu4rL39YVhRSKMzCaMNBSwSJi17t8LtAOW94WQTkhQCEhlMukFU2AtWOBW3zGIrvg85XRS+w0nuGxKw==",
"sha512": "sha512-NhaDvIaNRZIDZYbEGWZ+TJujRRiYfWRFwAOMMiKshw/oldvxWXPyjPaeRz+dqxg3RKXacPNhovTzmLXjI0TY1A==",
"path": "microsoft.management.infrastructure/1.0.0",
"hashPath": "microsoft.management.infrastructure.1.0.0.nupkg.sha512"
},
@@ -978,7 +978,7 @@
"System.Runtime.CompilerServices.VisualC/4.3.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-/dcn1oXqK/p/VnTYWNSf4OXlFIfzCRE/kqWz4+/r5B2S4zlKifB1FqklEEYs5zmE1JE3syvrJ5U4syOwsDQZbA==",
"sha512": "sha512-Wi1MPwneonOT11JvxZLvlvHSqQOuSci50KwWZ5JHMujjIrpyYH/ZELCqGB3fAXRvyFj61UE9PcE8rt+C40Vg9A==",
"path": "system.runtime.compilerservices.visualc/4.3.0",
"hashPath": "system.runtime.compilerservices.visualc.4.3.0.nupkg.sha512"
},
@@ -1041,7 +1041,7 @@
"System.Security.SecureString/4.3.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-PnXp38O9q/2Oe4iZHMH60kinScv6QiiL2XH54Pj2t0Y6c2zKPEiAZsM/M3wBOHLNTBDFP0zfy13WN2M0qFz5jg==",
"sha512": "sha512-VQRz+JB9J9NVIKT7ZpIvDUIhq6nNhKfoo1sWLwBvbat+A78FIUS54XXn9a+xu2VFXfWpR8vn6LenYqNKAuq0Eg==",
"path": "system.security.securestring/4.3.0",
"hashPath": "system.security.securestring.4.3.0.nupkg.sha512"
},
Binary file not shown.
Binary file not shown.
@@ -263,7 +263,7 @@ public DbaInstanceParameter(string Name)
_NetworkProtocol = SqlConnectionProtocol.NP;
return;
}

string tempString = Name.Trim();
tempString = Regex.Replace(tempString, @"^\[(.*)\]$", "$1");

@@ -321,7 +321,7 @@ public DbaInstanceParameter(string Name)
_Port = tempParam.Port;
}
_NetworkProtocol = tempParam.NetworkProtocol;

if (UtilityHost.IsLike(tempString, @"(localdb)\*"))
_NetworkProtocol = SqlConnectionProtocol.NP;

@@ -544,38 +544,25 @@ public DbaInstanceParameter(object Input)
switch (typeName)
{
case "microsoft.sqlserver.management.smo.server":
try
{
if (tempInput.Properties["ServerType"] != null && (string)tempInput.Properties["ServerType"].Value.ToString() == "SqlAzureDatabase")
_ComputerName = (new DbaInstanceParameter((string)tempInput.Properties["Name"].Value)).ComputerName;
else
{
if (tempInput.Properties["NetName"] != null)
_ComputerName = (string)tempInput.Properties["NetName"].Value;
else
_ComputerName = (new DbaInstanceParameter((string)tempInput.Properties["DomainInstanceName"].Value)).ComputerName;
}
_InstanceName = (string)tempInput.Properties["InstanceName"].Value;
PSObject tempObject = new PSObject(tempInput.Properties["ConnectionContext"].Value);
// the extra checks break azure by enumerating, causing a new
// connection and sometimes altering the connection string
// so let's try to avoid that
try
{
if (tempInput.Properties["ComputerName"] != null)
_ComputerName = (string)tempInput.Properties["ComputerName"].Value;

string tempConnectionString = (string)tempObject.Properties["ConnectionString"].Value;
tempConnectionString = tempConnectionString.Split(';')[0].Split('=')[1].Trim().Replace(" ", "");
//if (tempInput.Properties["NetPort"] != null)
// _Port = (Int32)tempInput.Properties["NetPort"].Value;

if (Regex.IsMatch(tempConnectionString, @",\d{1,5}$") && (tempConnectionString.Split(',').Length == 2))
{
try { Int32.TryParse(tempConnectionString.Split(',')[1], out _Port); }
catch (Exception e)
{
throw new PSArgumentException("Failed to parse port number on connection string: " + tempConnectionString, e);
}
if (_Port > 65535) { throw new PSArgumentException("Failed to parse port number on connection string: " + tempConnectionString); }
}
}
catch (Exception e)
{
throw new PSArgumentException("Failed to interpret input as Instance: " + Input + " : " + e.Message, e);
}
break;
}
catch (Exception e)
{
throw new PSArgumentException("Failed to interpret input as Instance: " + Input + " : " + e.Message, e);
}
if (String.IsNullOrEmpty(_ComputerName))
throw new PSArgumentException("Failed to interpret input as Instance, ComputerName empty: " + Input);
break;
case "microsoft.sqlserver.management.smo.linkedserver":
try
{
@@ -606,7 +593,7 @@ public DbaInstanceParameter(object Input)
case "microsoft.sqlserver.management.registeredservers.registeredserver":
try
{
//Pass the ServerName property of the SMO object to the string constrtuctor,
//Pass the ServerName property of the SMO object to the string constrtuctor,
//so we don't have to re-invent the wheel on instance name / port parsing
DbaInstanceParameter parm =
new DbaInstanceParameter((string) tempInput.Properties["ServerName"].Value);
@@ -6,9 +6,9 @@
<Company>sqlcollaborative</Company>
<Product>dbatools</Product>
<Description>The dbatools PowerShell Module library</Description>
<Copyright>Copyright © 2017</Copyright>
<AssemblyVersion>0.10.0.70</AssemblyVersion>
<FileVersion>0.10.0.70</FileVersion>
<Copyright>Copyright © 2019</Copyright>
<AssemblyVersion>0.10.0.71</AssemblyVersion>
<FileVersion>0.10.0.71</FileVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
@@ -123,7 +123,7 @@ function Add-DbaCmsRegServer {
Stop-Function -Message "Something went wrong and it's hard to explain, sorry. This basically shouldn't happen." -Continue
}

$server = $parentserver.ServerConnection.SqlConnectionObject
$server = $reggroup.ParentServer

if ($Pscmdlet.ShouldProcess($parentserver.SqlInstance, "Adding $ServerName")) {
try {
@@ -93,7 +93,7 @@ function Add-DbaCmsRegServerGroup {

foreach ($reggroup in $InputObject) {
$parentserver = Get-RegServerParent -InputObject $reggroup
$server = $parentserver.ServerConnection.ServerInstance.SqlConnectionObject
$server = $reggroup.ParentServer

if ($null -eq $parentserver) {
Stop-Function -Message "Something went wrong and it's hard to explain, sorry. This basically shouldn't happen." -Continue
@@ -105,7 +105,7 @@ function Add-DbaCmsRegServerGroup {
$newgroup.Description = $Description
$newgroup.Create()

Get-DbaCmsRegServerGroup -SqlInstance $parentserver.ServerConnection.SqlConnectionObject -Group (Get-RegServerGroupReverseParse -object $newgroup)
Get-DbaCmsRegServerGroup -SqlInstance $server -Group (Get-RegServerGroupReverseParse -object $newgroup)
$parentserver.ServerConnection.Disconnect()
} catch {
Stop-Function -Message "Failed to add $reggroup on $server" -ErrorRecord $_ -Continue
@@ -93,7 +93,7 @@ function Export-DbaCmsRegServer {
foreach ($object in $InputObject) {
try {
if ($object -is [Microsoft.SqlServer.Management.RegisteredServers.RegisteredServersStore]) {
$object = Get-DbaCmsRegServerGroup -SqlInstance $object.ServerConnection.SqlConnectionObject -Id 1
$object = Get-DbaCmsRegServerGroup -SqlInstance $object.ParentServer -Id 1
}

if ($object -is [Microsoft.SqlServer.Management.RegisteredServers.RegisteredServer]) {
@@ -140,7 +140,7 @@ function Get-DbaCmsRegServer {
}

if ($ExcludeGroup) {
$excluded = Get-DbaCmsRegServer $serverstore.ServerConnection.SqlConnectionObject -Group $ExcludeGroup
$excluded = Get-DbaCmsRegServer -SqlInstance $serverstore.ParentServer -Group $ExcludeGroup
Write-Message -Level Verbose -Message "Excluding $ExcludeGroup"
$servers = $servers | Where-Object { $_.Urn.Value -notin $excluded.Urn.Value }
}
@@ -162,6 +162,7 @@ function Get-DbaCmsRegServer {
Add-Member -Force -InputObject $server -MemberType NoteProperty -Name Group -value $groupname
Add-Member -Force -InputObject $server -MemberType NoteProperty -Name FQDN -Value $null
Add-Member -Force -InputObject $server -MemberType NoteProperty -Name IPAddress -Value $null
Add-Member -Force -InputObject $server -MemberType NoteProperty -Name ParentServer -Value $serverstore.ParentServer

if ($ResolveNetworkName) {
try {
@@ -75,7 +75,7 @@ function Get-DbaCmsRegServerGroup {
process {
foreach ($instance in $SqlInstance) {
try {
$server = Get-DbaCmsRegServerStore -SqlInstance $instance -SqlCredential $SqlCredential -EnableException
$serverstore = Get-DbaCmsRegServerStore -SqlInstance $instance -SqlCredential $SqlCredential -EnableException
} catch {
Stop-Function -Message "Cannot access Central Management Server '$instance'" -ErrorRecord $_ -Continue
}
@@ -96,7 +96,7 @@ function Get-DbaCmsRegServerGroup {
if ($currentgroup -match '\\') {
$split = $currentgroup.Split('\\')
$i = 0
$groupobject = $server.DatabaseEngineServerGroup
$groupobject = $serverstore.DatabaseEngineServerGroup
do {
if ($groupobject) {
$groupobject = $groupobject.ServerGroups[$split[$i]]
@@ -109,7 +109,7 @@ function Get-DbaCmsRegServerGroup {
}
} else {
try {
$thisgroup = $server.DatabaseEngineServerGroup.ServerGroups[$currentgroup]
$thisgroup = $serverstore.DatabaseEngineServerGroup.ServerGroups[$currentgroup]
if ($thisgroup) {
Write-Message -Level Verbose -Message "Added $($thisgroup.Name)"
$groups += $thisgroup
@@ -122,33 +122,34 @@ function Get-DbaCmsRegServerGroup {
}
} else {
Write-Message -Level Verbose -Message "Added all root server groups"
$groups = $server.DatabaseEngineServerGroup.ServerGroups
$groups = $serverstore.DatabaseEngineServerGroup.ServerGroups
}

if ($Group -eq 'DatabaseEngineServerGroup') {
Write-Message -Level Verbose -Message "Added root group"
$groups = $server.DatabaseEngineServerGroup
$groups = $serverstore.DatabaseEngineServerGroup
}

if ($ExcludeGroup) {
$excluded = Get-DbaCmsRegServer $server -Group $ExcludeGroup
$excluded = Get-DbaCmsRegServer -SqlInstance $serverstore.ParentServer -Group $ExcludeGroup
Write-Message -Level Verbose -Message "Excluding $ExcludeGroup"
$groups = $groups | Where-Object { $_.Urn.Value -notin $excluded.Urn.Value }
}

if ($Id) {
Write-Message -Level Verbose -Message "Filtering for id $Id. Id 1 = default."
if ($Id -eq 1) {
$groups = $server.DatabaseEngineServerGroup | Where-Object Id -in $Id
$groups = $serverstore.DatabaseEngineServerGroup | Where-Object Id -in $Id
} else {
$groups = $server.DatabaseEngineServerGroup.GetDescendantRegisteredServers().Parent | Where-Object Id -in $Id
$groups = $serverstore.DatabaseEngineServerGroup.GetDescendantRegisteredServers().Parent | Where-Object Id -in $Id
}
}
$server.ServerConnection.Disconnect()
$serverstore.ServerConnection.Disconnect()
foreach ($groupobject in $groups) {
Add-Member -Force -InputObject $groupobject -MemberType NoteProperty -Name ComputerName -value $server.ComputerName
Add-Member -Force -InputObject $groupobject -MemberType NoteProperty -Name InstanceName -value $server.InstanceName
Add-Member -Force -InputObject $groupobject -MemberType NoteProperty -Name SqlInstance -value $server.SqlInstance
Add-Member -Force -InputObject $groupobject -MemberType NoteProperty -Name ComputerName -value $serverstore.ComputerName
Add-Member -Force -InputObject $groupobject -MemberType NoteProperty -Name InstanceName -value $serverstore.InstanceName
Add-Member -Force -InputObject $groupobject -MemberType NoteProperty -Name SqlInstance -value $serverstore.SqlInstance
Add-Member -Force -InputObject $groupobject -MemberType NoteProperty -Name ParentServer -value $serverstore.ParentServer

Select-DefaultView -InputObject $groupobject -Property ComputerName, InstanceName, SqlInstance, Name, DisplayName, Description, ServerGroups, RegisteredServers
}
@@ -67,8 +67,8 @@ function Get-DbaCmsRegServerStore {
Add-Member -Force -InputObject $store -MemberType NoteProperty -Name ComputerName -value $server.ComputerName
Add-Member -Force -InputObject $store -MemberType NoteProperty -Name InstanceName -value $server.ServiceName
Add-Member -Force -InputObject $store -MemberType NoteProperty -Name SqlInstance -value $server.DomainInstanceName

Select-DefaultView -InputObject $store -ExcludeProperty ServerConnection, DomainInstanceName, DomainName, Urn, Properties, Metadata, Parent, ConnectionContext, PropertyMetadataChanged, PropertyChanged
Add-Member -Force -InputObject $store -MemberType NoteProperty -Name ParentServer -value $server
Select-DefaultView -InputObject $store -ExcludeProperty ServerConnection, DomainInstanceName, DomainName, Urn, Properties, Metadata, Parent, ConnectionContext, PropertyMetadataChanged, PropertyChanged, ParentServer
}
}
end {
@@ -94,7 +94,7 @@ function Move-DbaCmsRegServer {
Stop-Function -Message "Something went wrong and it's hard to explain, sorry. This basically shouldn't happen." -Continue
}

$server = $parentserver.ServerConnection.SqlConnectionObject
$server = $regserver.ParentServer

if ((Test-Bound -ParameterName NewGroup)) {
$group = Get-DbaCmsRegServerGroup -SqlInstance $server -Group $NewGroup
@@ -88,7 +88,7 @@ function Move-DbaCmsRegServerGroup {
Stop-Function -Message "Something went wrong and it's hard to explain, sorry. This basically shouldn't happen." -Continue
}

$server = $parentserver.ServerConnection.SqlConnectionObject
$server = $regservergroup.ParentServer

if ($NewGroup -eq 'Default') {
$groupobject = Get-DbaCmsRegServerGroup -SqlInstance $server -Id 1
@@ -5,7 +5,7 @@ Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
Describe "$CommandName Unit Tests" -Tags "UnitTests" {
Context "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance','SqlCredential','ServerName','Name','Description','Group','InputObject','EnableException'
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'ServerName', 'Name', 'Description', 'Group', 'InputObject', 'EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
@@ -5,7 +5,7 @@ Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
Describe "$CommandName Unit Tests" -Tags "UnitTests" {
Context "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance','SqlCredential','Name','ServerName','Group','ExcludeGroup','Id','IncludeSelf','ExcludeCmsServer','ResolveNetworkName','EnableException'
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Name', 'ServerName', 'Group', 'ExcludeGroup', 'Id', 'IncludeSelf', 'ExcludeCmsServer', 'ResolveNetworkName', 'EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
@@ -27,6 +27,7 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' {
$obj = [PSCustomObject]@{
Name = 'BASEName'
NetName = 'BASENetName'
ComputerName = 'BASEComputerName'
InstanceName = 'BASEInstanceName'
DomainInstanceName = 'BASEDomainInstanceName'
InstallDataDirectory = 'BASEInstallDataDirectory'
@@ -67,6 +68,7 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' {
$obj = [PSCustomObject]@{
Name = 'BASEName'
NetName = 'BASENetName'
ComputerName = 'BASEComputerName'
InstanceName = 'BASEInstanceName'
DomainInstanceName = 'BASEDomainInstanceName'
InstallDataDirectory = 'BASEInstallDataDirectory'
Oops, something went wrong.

0 comments on commit d21cdc2

Please sign in to comment.
You can’t perform that action at this time.