|
| 1 | +<# |
| 2 | + .SYNOPSIS |
| 3 | + Gets the report server installations registered in the database. |
| 4 | +
|
| 5 | + .DESCRIPTION |
| 6 | + Gets the Reporting Services installations registered in the report |
| 7 | + server database by calling the `ListReportServersInDatabase` method |
| 8 | + on the `MSReportServer_ConfigurationSetting` CIM instance. |
| 9 | +
|
| 10 | + This command returns information about all report server installations |
| 11 | + that are configured to use the same report server database, which is |
| 12 | + useful in scale-out deployment scenarios. |
| 13 | +
|
| 14 | + The configuration CIM instance can be obtained using the |
| 15 | + `Get-SqlDscRSConfiguration` command and passed via the pipeline. |
| 16 | +
|
| 17 | + .PARAMETER Configuration |
| 18 | + Specifies the `MSReportServer_ConfigurationSetting` CIM instance for |
| 19 | + the Reporting Services instance. This can be obtained using the |
| 20 | + `Get-SqlDscRSConfiguration` command. This parameter accepts pipeline |
| 21 | + input. |
| 22 | +
|
| 23 | + .EXAMPLE |
| 24 | + Get-SqlDscRSConfiguration -InstanceName 'SSRS' | Get-SqlDscRSDatabaseInstallation |
| 25 | +
|
| 26 | + Gets all report server installations registered in the database. |
| 27 | +
|
| 28 | + .EXAMPLE |
| 29 | + $config = Get-SqlDscRSConfiguration -InstanceName 'SSRS' |
| 30 | + Get-SqlDscRSDatabaseInstallation -Configuration $config |
| 31 | +
|
| 32 | + Gets report server installations using a stored configuration object. |
| 33 | +
|
| 34 | + .INPUTS |
| 35 | + `Microsoft.Management.Infrastructure.CimInstance` |
| 36 | +
|
| 37 | + Accepts MSReportServer_ConfigurationSetting CIM instance via pipeline. |
| 38 | +
|
| 39 | + .OUTPUTS |
| 40 | + `System.Management.Automation.PSCustomObject` |
| 41 | +
|
| 42 | + Returns objects with properties: InstallationID, MachineName, |
| 43 | + InstanceName, and IsInitialized. |
| 44 | +
|
| 45 | + .NOTES |
| 46 | + This command calls the CIM/WMI provider method `ListReportServersInDatabase` |
| 47 | + using `Invoke-RsCimMethod`. |
| 48 | +
|
| 49 | + .LINK |
| 50 | + https://docs.microsoft.com/en-us/sql/reporting-services/wmi-provider-library-reference/configurationsetting-method-listreportserversindatabase |
| 51 | +#> |
| 52 | +function Get-SqlDscRSDatabaseInstallation |
| 53 | +{ |
| 54 | + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the examples use pipeline input the rule cannot validate.')] |
| 55 | + [CmdletBinding()] |
| 56 | + [OutputType([System.Management.Automation.PSCustomObject])] |
| 57 | + param |
| 58 | + ( |
| 59 | + [Parameter(Mandatory = $true, ValueFromPipeline = $true)] |
| 60 | + [System.Object] |
| 61 | + $Configuration |
| 62 | + ) |
| 63 | + |
| 64 | + process |
| 65 | + { |
| 66 | + $instanceName = $Configuration.InstanceName |
| 67 | + |
| 68 | + Write-Verbose -Message ($script:localizedData.Get_SqlDscRSDatabaseInstallation_Getting -f $instanceName) |
| 69 | + |
| 70 | + $invokeRsCimMethodParameters = @{ |
| 71 | + CimInstance = $Configuration |
| 72 | + MethodName = 'ListReportServersInDatabase' |
| 73 | + } |
| 74 | + |
| 75 | + try |
| 76 | + { |
| 77 | + $result = Invoke-RsCimMethod @invokeRsCimMethodParameters -ErrorAction 'Stop' |
| 78 | + |
| 79 | + <# |
| 80 | + The WMI method returns: |
| 81 | + - Length: Number of entries in the arrays |
| 82 | + - InstallationID: Array of installation IDs |
| 83 | + - MachineName: Array of machine names |
| 84 | + - InstanceName: Array of instance names |
| 85 | + - IsInitialized: Array of initialization states |
| 86 | + #> |
| 87 | + if ($result.Length -gt 0) |
| 88 | + { |
| 89 | + for ($i = 0; $i -lt $result.Length; $i++) |
| 90 | + { |
| 91 | + [PSCustomObject] @{ |
| 92 | + InstallationID = $result.InstallationIDs[$i] |
| 93 | + MachineName = $result.MachineNames[$i] |
| 94 | + InstanceName = $result.InstanceNames[$i] |
| 95 | + IsInitialized = $result.IsInitialized[$i] |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + catch |
| 101 | + { |
| 102 | + $PSCmdlet.ThrowTerminatingError( |
| 103 | + [System.Management.Automation.ErrorRecord]::new( |
| 104 | + ($script:localizedData.Get_SqlDscRSDatabaseInstallation_FailedToGet -f $instanceName, $_.Exception.Message), |
| 105 | + 'GSRSDI0001', |
| 106 | + [System.Management.Automation.ErrorCategory]::InvalidOperation, |
| 107 | + $Configuration |
| 108 | + ) |
| 109 | + ) |
| 110 | + } |
| 111 | + } |
| 112 | +} |
0 commit comments