forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAdd-SqlDscRSUrlReservation.ps1
More file actions
171 lines (134 loc) · 6.27 KB
/
Add-SqlDscRSUrlReservation.ps1
File metadata and controls
171 lines (134 loc) · 6.27 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<#
.SYNOPSIS
Adds a URL reservation for SQL Server Reporting Services.
.DESCRIPTION
Adds a URL reservation for SQL Server Reporting Services or
Power BI Report Server by calling the `ReserveUrl` method on
the `MSReportServer_ConfigurationSetting` CIM instance.
This command reserves a URL for a specific application in the
Reporting Services instance. The application can be the Report Server
Web Service, the Reports web application (SQL Server 2016+), or the
Report Manager (SQL Server 2014 and earlier).
The configuration CIM instance can be obtained using the
`Get-SqlDscRSConfiguration` command and passed via the pipeline.
.PARAMETER Configuration
Specifies the `MSReportServer_ConfigurationSetting` CIM instance for
the Reporting Services instance. This can be obtained using the
`Get-SqlDscRSConfiguration` command. This parameter accepts pipeline
input.
.PARAMETER Application
Specifies the application for which to reserve the URL. Valid values
are:
- 'ReportServerWebService': The Report Server Web Service.
- 'ReportServerWebApp': The Reports web application (SQL Server 2016+).
- 'ReportManager': The Report Manager (SQL Server 2014 and earlier).
.PARAMETER UrlString
Specifies the URL string to reserve. The URL string format is typically
'http://+:80' or 'https://+:443' where the plus sign (+) is a wildcard
that matches all hostnames.
.PARAMETER Lcid
Specifies the language code identifier (LCID) for the URL reservation.
If not specified, defaults to the operating system language. Common
values include 1033 for English (US).
.PARAMETER PassThru
If specified, returns the configuration CIM instance after adding
the URL reservation.
.PARAMETER Force
If specified, suppresses the confirmation prompt.
.EXAMPLE
Get-SqlDscRSConfiguration -InstanceName 'SSRS' | Add-SqlDscRSUrlReservation -Application 'ReportServerWebService' -UrlString 'http://+:80'
Adds a URL reservation for the Report Server Web Service on port 80.
.EXAMPLE
$config = Get-SqlDscRSConfiguration -InstanceName 'SSRS'
Add-SqlDscRSUrlReservation -Configuration $config -Application 'ReportServerWebApp' -UrlString 'https://+:443' -Confirm:$false
Adds a URL reservation for the Reports web application on port 443
without confirmation.
.EXAMPLE
Get-SqlDscRSConfiguration -InstanceName 'SSRS' | Add-SqlDscRSUrlReservation -Application 'ReportServerWebService' -UrlString 'http://+:8080' -Lcid 1033 -PassThru
Adds a URL reservation with a specific LCID and returns the configuration
CIM instance.
.INPUTS
`Microsoft.Management.Infrastructure.CimInstance`
Accepts MSReportServer_ConfigurationSetting CIM instance via pipeline.
.OUTPUTS
None. By default, this command does not generate any output.
.OUTPUTS
`Microsoft.Management.Infrastructure.CimInstance`
When PassThru is specified, returns the MSReportServer_ConfigurationSetting
CIM instance.
.NOTES
The Reporting Services service may need to be restarted for the change
to take effect.
.LINK
https://docs.microsoft.com/en-us/sql/reporting-services/wmi-provider-library-reference/configurationsetting-method-reserveurl
#>
function Add-SqlDscRSUrlReservation
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the examples use pipeline input the rule cannot validate.')]
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
[OutputType([System.Object])]
param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[System.Object]
$Configuration,
[Parameter(Mandatory = $true)]
[ValidateSet('ReportServerWebService', 'ReportServerWebApp', 'ReportManager')]
[System.String]
$Application,
[Parameter(Mandatory = $true)]
[System.String]
$UrlString,
[Parameter()]
[System.Int32]
$Lcid,
[Parameter()]
[System.Management.Automation.SwitchParameter]
$PassThru,
[Parameter()]
[System.Management.Automation.SwitchParameter]
$Force
)
process
{
if ($Force.IsPresent -and -not $Confirm)
{
$ConfirmPreference = 'None'
}
$instanceName = $Configuration.InstanceName
if (-not $PSBoundParameters.ContainsKey('Lcid'))
{
$Lcid = (Get-OperatingSystem).OSLanguage
}
Write-Verbose -Message ($script:localizedData.Add_SqlDscRSUrlReservation_Adding -f $UrlString, $Application, $instanceName)
$descriptionMessage = $script:localizedData.Add_SqlDscRSUrlReservation_ShouldProcessDescription -f $UrlString, $Application, $instanceName
$confirmationMessage = $script:localizedData.Add_SqlDscRSUrlReservation_ShouldProcessConfirmation -f $UrlString, $Application
$captionMessage = $script:localizedData.Add_SqlDscRSUrlReservation_ShouldProcessCaption
if ($PSCmdlet.ShouldProcess($descriptionMessage, $confirmationMessage, $captionMessage))
{
$invokeRsCimMethodParameters = @{
CimInstance = $Configuration
MethodName = 'ReserveUrl'
Arguments = @{
Application = $Application
UrlString = $UrlString
Lcid = $Lcid
}
}
try
{
$null = Invoke-RsCimMethod @invokeRsCimMethodParameters
}
catch
{
$errorMessage = $script:localizedData.Add_SqlDscRSUrlReservation_FailedToAdd -f $instanceName, $_.Exception.Message
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'ASRUR0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration
$PSCmdlet.ThrowTerminatingError($errorRecord)
}
}
if ($PassThru.IsPresent)
{
return $Configuration
}
}
}