forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGet-SqlDscRSConfiguration.ps1
More file actions
131 lines (98 loc) · 4.93 KB
/
Get-SqlDscRSConfiguration.ps1
File metadata and controls
131 lines (98 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<#
.SYNOPSIS
Gets the SQL Server Reporting Services configuration CIM instance.
.DESCRIPTION
Gets the SQL Server Reporting Services or Power BI Report Server
configuration CIM instance (`MSReportServer_ConfigurationSetting`).
This CIM instance can be used with other commands that manage
Reporting Services configuration, such as `Enable-SqlDscRsSecureConnection`
and `Disable-SqlDscRsSecureConnection`.
The configuration CIM instance provides access to properties like
`SecureConnectionLevel`, `DatabaseServerName`, `VirtualDirectoryReportServer`,
and methods for managing Reporting Services configuration.
.PARAMETER InstanceName
Specifies the name of the Reporting Services instance. This is a
mandatory parameter.
.PARAMETER Version
Specifies the major version number of the Reporting Services instance.
If not specified, the version is automatically detected using
`Get-SqlDscRSSetupConfiguration`.
.EXAMPLE
Get-SqlDscRSConfiguration -InstanceName 'SSRS'
Returns the configuration CIM instance for the SSRS instance. The version
is automatically detected.
.EXAMPLE
Get-SqlDscRSConfiguration -InstanceName 'SSRS' -Version 15
Returns the configuration CIM instance for the SSRS instance with
explicit version 15 (SQL Server 2019).
.EXAMPLE
Get-SqlDscRSConfiguration -InstanceName 'SSRS' | Enable-SqlDscRsSecureConnection
Gets the configuration CIM instance for the SSRS instance and enables
secure connection using the pipeline.
.INPUTS
None.
.OUTPUTS
`Microsoft.Management.Infrastructure.CimInstance`
Returns the MSReportServer_ConfigurationSetting CIM instance for the
specified Reporting Services instance.
#>
function Get-SqlDscRSConfiguration
{
[CmdletBinding()]
[OutputType([Microsoft.Management.Infrastructure.CimInstance])]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$InstanceName,
[Parameter()]
[System.Int32]
$Version
)
if (-not $PSBoundParameters.ContainsKey('Version'))
{
Write-Verbose -Message ($script:localizedData.Get_SqlDscRSConfiguration_DetectingVersion -f $InstanceName)
$rsSetupConfiguration = Get-SqlDscRSSetupConfiguration -InstanceName $InstanceName
if (-not $rsSetupConfiguration)
{
$errorMessage = $script:localizedData.Get_SqlDscRSConfiguration_InstanceNotFound -f $InstanceName
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'GSRSCD0001' -ErrorCategory 'ObjectNotFound' -TargetObject $InstanceName
$PSCmdlet.ThrowTerminatingError($errorRecord)
}
if ([System.String]::IsNullOrEmpty($rsSetupConfiguration.CurrentVersion))
{
$errorMessage = $script:localizedData.Get_SqlDscRSConfiguration_VersionNotFound -f $InstanceName
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'GSRSCD0002' -ErrorCategory 'ObjectNotFound' -TargetObject $InstanceName
$PSCmdlet.ThrowTerminatingError($errorRecord)
}
$Version = ([System.Version] $rsSetupConfiguration.CurrentVersion).Major
}
Write-Verbose -Message ($script:localizedData.Get_SqlDscRSConfiguration_GettingConfiguration -f $InstanceName, $Version)
$getCimInstanceParameters = @{
ClassName = 'MSReportServer_ConfigurationSetting'
Namespace = 'root\Microsoft\SQLServer\ReportServer\RS_{0}\v{1}\Admin' -f $InstanceName, $Version
ErrorAction = 'Stop'
}
try
{
$reportingServicesConfiguration = Get-CimInstance @getCimInstanceParameters
}
catch
{
$errorMessage = $script:localizedData.Get_SqlDscRSConfiguration_FailedToGetConfiguration -f $InstanceName, $_.Exception.Message
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ -PassThru) -ErrorId 'GSRSCD0003' -ErrorCategory 'InvalidOperation' -TargetObject $InstanceName
$PSCmdlet.ThrowTerminatingError($errorRecord)
}
# Filter to ensure we get the correct instance if multiple are returned.
$reportingServicesConfiguration = $reportingServicesConfiguration |
Where-Object -FilterScript {
$_.InstanceName -eq $InstanceName
}
if (-not $reportingServicesConfiguration)
{
$errorMessage = $script:localizedData.Get_SqlDscRSConfiguration_ConfigurationNotFound -f $InstanceName
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'GSRSCD0004' -ErrorCategory 'ObjectNotFound' -TargetObject $InstanceName
$PSCmdlet.ThrowTerminatingError($errorRecord)
}
return $reportingServicesConfiguration
}