Skip to content

Commit

Permalink
Registered Servers - fix for SYSTEM (#8459)
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee authored Jul 24, 2022
1 parent 2c18b76 commit f650f7d
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 6 deletions.
189 changes: 189 additions & 0 deletions bin/RegSrvr.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<?xml version="1.0"?>
<model xmlns="http://schemas.serviceml.org/smlif/2007/02">
<identity>
<name>urn:uuid:96fe1236-abf6-4a57-b54d-e9baab394fd1</name>
<baseURI>http://documentcollection/</baseURI>
</identity>
<xs:bufferSchema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<definitions xmlns:sfc="http://schemas.microsoft.com/sqlserver/sfc/serialization/2007/08">
<document>
<docinfo>
<aliases>
<alias>/system/schema/RegisteredServers</alias>
</aliases>
<sfc:version DomainVersion="1" />
</docinfo>
<data>
<xs:schema targetNamespace="http://schemas.microsoft.com/sqlserver/RegisteredServers/2007/08" xmlns:sfc="http://schemas.microsoft.com/sqlserver/sfc/serialization/2007/08" xmlns:sml="http://schemas.serviceml.org/sml/2007/02" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="RegisteredServersStore">
<xs:complexType>
<xs:sequence>
<xs:any namespace="http://schemas.microsoft.com/sqlserver/RegisteredServers/2007/08" processContents="skip" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ServerGroup">
<xs:complexType>
<xs:sequence>
<xs:any namespace="http://schemas.microsoft.com/sqlserver/RegisteredServers/2007/08" processContents="skip" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<RegisteredServers:bufferData xmlns:RegisteredServers="http://schemas.microsoft.com/sqlserver/RegisteredServers/2007/08">
<instances xmlns:sfc="http://schemas.microsoft.com/sqlserver/sfc/serialization/2007/08">
<document>
<docinfo>
<aliases>
<alias>/RegisteredServersStore</alias>
</aliases>
<sfc:version DomainVersion="1" />
</docinfo>
<data>
<RegisteredServers:RegisteredServersStore xmlns:RegisteredServers="http://schemas.microsoft.com/sqlserver/RegisteredServers/2007/08" xmlns:sfc="http://schemas.microsoft.com/sqlserver/sfc/serialization/2007/08" xmlns:sml="http://schemas.serviceml.org/sml/2007/02" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<RegisteredServers:ServerGroups>
<sfc:Collection>
<sfc:Reference sml:ref="true">
<sml:Uri>/RegisteredServersStore/ServerGroup/AnalysisServicesServerGroup</sml:Uri>
</sfc:Reference>
<sfc:Reference sml:ref="true">
<sml:Uri>/RegisteredServersStore/ServerGroup/CentralManagementServerGroup</sml:Uri>
</sfc:Reference>
<sfc:Reference sml:ref="true">
<sml:Uri>/RegisteredServersStore/ServerGroup/DatabaseEngineServerGroup</sml:Uri>
</sfc:Reference>
<sfc:Reference sml:ref="true">
<sml:Uri>/RegisteredServersStore/ServerGroup/IntegrationServicesServerGroup</sml:Uri>
</sfc:Reference>
<sfc:Reference sml:ref="true">
<sml:Uri>/RegisteredServersStore/ServerGroup/ReportingServicesServerGroup</sml:Uri>
</sfc:Reference>
<sfc:Reference sml:ref="true">
<sml:Uri>/RegisteredServersStore/ServerGroup/SqlServerCompactEditionServerGroup</sml:Uri>
</sfc:Reference>
</sfc:Collection>
</RegisteredServers:ServerGroups>
</RegisteredServers:RegisteredServersStore>
</data>
</document>
<document>
<docinfo>
<aliases>
<alias>/RegisteredServersStore/ServerGroup/AnalysisServicesServerGroup</alias>
</aliases>
<sfc:version DomainVersion="1" />
</docinfo>
<data>
<RegisteredServers:ServerGroup xmlns:RegisteredServers="http://schemas.microsoft.com/sqlserver/RegisteredServers/2007/08" xmlns:sfc="http://schemas.microsoft.com/sqlserver/sfc/serialization/2007/08" xmlns:sml="http://schemas.serviceml.org/sml/2007/02" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<RegisteredServers:Parent>
<sfc:Reference sml:ref="true">
<sml:Uri>/RegisteredServersStore</sml:Uri>
</sfc:Reference>
</RegisteredServers:Parent>
<RegisteredServers:Name type="string">AnalysisServicesServerGroup</RegisteredServers:Name>
<RegisteredServers:ServerType type="ServerType">AnalysisServices</RegisteredServers:ServerType>
</RegisteredServers:ServerGroup>
</data>
</document>
<document>
<docinfo>
<aliases>
<alias>/RegisteredServersStore/ServerGroup/CentralManagementServerGroup</alias>
</aliases>
<sfc:version DomainVersion="1" />
</docinfo>
<data>
<RegisteredServers:ServerGroup xmlns:RegisteredServers="http://schemas.microsoft.com/sqlserver/RegisteredServers/2007/08" xmlns:sfc="http://schemas.microsoft.com/sqlserver/sfc/serialization/2007/08" xmlns:sml="http://schemas.serviceml.org/sml/2007/02" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<RegisteredServers:Parent>
<sfc:Reference sml:ref="true">
<sml:Uri>/RegisteredServersStore</sml:Uri>
</sfc:Reference>
</RegisteredServers:Parent>
<RegisteredServers:Name type="string">CentralManagementServerGroup</RegisteredServers:Name>
<RegisteredServers:ServerType type="ServerType">DatabaseEngine</RegisteredServers:ServerType>
</RegisteredServers:ServerGroup>
</data>
</document>
<document>
<docinfo>
<aliases>
<alias>/RegisteredServersStore/ServerGroup/DatabaseEngineServerGroup</alias>
</aliases>
<sfc:version DomainVersion="1" />
</docinfo>
<data>
<RegisteredServers:ServerGroup xmlns:RegisteredServers="http://schemas.microsoft.com/sqlserver/RegisteredServers/2007/08" xmlns:sfc="http://schemas.microsoft.com/sqlserver/sfc/serialization/2007/08" xmlns:sml="http://schemas.serviceml.org/sml/2007/02" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<RegisteredServers:Parent>
<sfc:Reference sml:ref="true">
<sml:Uri>/RegisteredServersStore</sml:Uri>
</sfc:Reference>
</RegisteredServers:Parent>
<RegisteredServers:Name type="string">DatabaseEngineServerGroup</RegisteredServers:Name>
<RegisteredServers:ServerType type="ServerType">DatabaseEngine</RegisteredServers:ServerType>
</RegisteredServers:ServerGroup>
</data>
</document>
<document>
<docinfo>
<aliases>
<alias>/RegisteredServersStore/ServerGroup/IntegrationServicesServerGroup</alias>
</aliases>
<sfc:version DomainVersion="1" />
</docinfo>
<data>
<RegisteredServers:ServerGroup xmlns:RegisteredServers="http://schemas.microsoft.com/sqlserver/RegisteredServers/2007/08" xmlns:sfc="http://schemas.microsoft.com/sqlserver/sfc/serialization/2007/08" xmlns:sml="http://schemas.serviceml.org/sml/2007/02" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<RegisteredServers:Parent>
<sfc:Reference sml:ref="true">
<sml:Uri>/RegisteredServersStore</sml:Uri>
</sfc:Reference>
</RegisteredServers:Parent>
<RegisteredServers:Name type="string">IntegrationServicesServerGroup</RegisteredServers:Name>
<RegisteredServers:ServerType type="ServerType">IntegrationServices</RegisteredServers:ServerType>
</RegisteredServers:ServerGroup>
</data>
</document>
<document>
<docinfo>
<aliases>
<alias>/RegisteredServersStore/ServerGroup/ReportingServicesServerGroup</alias>
</aliases>
<sfc:version DomainVersion="1" />
</docinfo>
<data>
<RegisteredServers:ServerGroup xmlns:RegisteredServers="http://schemas.microsoft.com/sqlserver/RegisteredServers/2007/08" xmlns:sfc="http://schemas.microsoft.com/sqlserver/sfc/serialization/2007/08" xmlns:sml="http://schemas.serviceml.org/sml/2007/02" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<RegisteredServers:Parent>
<sfc:Reference sml:ref="true">
<sml:Uri>/RegisteredServersStore</sml:Uri>
</sfc:Reference>
</RegisteredServers:Parent>
<RegisteredServers:Name type="string">ReportingServicesServerGroup</RegisteredServers:Name>
<RegisteredServers:ServerType type="ServerType">ReportingServices</RegisteredServers:ServerType>
</RegisteredServers:ServerGroup>
</data>
</document>
<document>
<docinfo>
<aliases>
<alias>/RegisteredServersStore/ServerGroup/SqlServerCompactEditionServerGroup</alias>
</aliases>
<sfc:version DomainVersion="1" />
</docinfo>
<data>
<RegisteredServers:ServerGroup xmlns:RegisteredServers="http://schemas.microsoft.com/sqlserver/RegisteredServers/2007/08" xmlns:sfc="http://schemas.microsoft.com/sqlserver/sfc/serialization/2007/08" xmlns:sml="http://schemas.serviceml.org/sml/2007/02" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<RegisteredServers:Parent>
<sfc:Reference sml:ref="true">
<sml:Uri>/RegisteredServersStore</sml:Uri>
</sfc:Reference>
</RegisteredServers:Parent>
<RegisteredServers:Name type="string">SqlServerCompactEditionServerGroup</RegisteredServers:Name>
<RegisteredServers:ServerType type="ServerType">SqlServerCompactEdition</RegisteredServers:ServerType>
</RegisteredServers:ServerGroup>
</data>
</document>
</instances>
</RegisteredServers:bufferData>
</xs:schema>
</data>
</document>
</definitions>
</xs:bufferSchema>
</model>
7 changes: 5 additions & 2 deletions functions/Add-DbaRegServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ function Add-DbaRegServer {
return
}
if (-not $Name) {
$Name = $ServerName
if ($ServerObject) {
$Name = $ServerObject.Name
} else {
$Name = $ServerName
}
}

if ((-not $SqlInstance -and -not $InputObject) -or $ServerObject) {
Expand Down Expand Up @@ -170,7 +174,6 @@ function Add-DbaRegServer {
$InputObject += Add-DbaRegServerGroup -SqlInstance $instance -SqlCredential $SqlCredential -Name $Group
}
}

} else {
$InputObject += Get-DbaRegServerGroup -SqlInstance $instance -SqlCredential $SqlCredential -Id 1
}
Expand Down
10 changes: 6 additions & 4 deletions functions/Get-DbaRegServerStore.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ function Get-DbaRegServerStore {
if (-not $PSBoundParameters.SqlInstance) {
$file = [Microsoft.SqlServer.Management.RegisteredServers.RegisteredServersStore]::LocalFileStore.DomainInstanceName
if ($file) {
if ((Test-Path -Path $file)) {
$class = [Microsoft.SqlServer.Management.RegisteredServers.RegisteredServersStore]
$initMethod = $class.GetMethod('InitChildObjects', [Reflection.BindingFlags]'Static,NonPublic')
$initMethod.Invoke($null, @($file))
if (-not (Test-Path -Path $file)) {
$regfile = Join-DbaPath -Path $script:PSModuleRoot -ChildPath bin, RegSrvr.xml
Copy-Item -Path $regfile -Destination $file -Force
}
$class = [Microsoft.SqlServer.Management.RegisteredServers.RegisteredServersStore]
$initMethod = $class.GetMethod('InitChildObjects', [Reflection.BindingFlags]'Static,NonPublic')
$initMethod.Invoke($null, @($file))
}
}
}
Expand Down

0 comments on commit f650f7d

Please sign in to comment.