forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInvoke-ReportServerSetupAction.ps1
More file actions
366 lines (279 loc) · 12 KB
/
Invoke-ReportServerSetupAction.ps1
File metadata and controls
366 lines (279 loc) · 12 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<#
.SYNOPSIS
Executes setup using the provided setup executable.
.DESCRIPTION
Executes Reporting Services or BI Report Server setup using the provided setup executable.
See the link in the commands help for information on each parameter.
.PARAMETER Install
Specifies that a new installation should be performed.
.PARAMETER Uninstall
Specifies that an uninstallation should be performed.
.PARAMETER Repair
Specifies that a repair should be performed on an existing installation.
.PARAMETER AcceptLicensingTerms
Required parameter to be able to run unattended install. By specifying this
parameter you acknowledge the acceptance of all license terms and notices for
the specified features, the terms and notices that the setup executable
normally asks for.
.PARAMETER MediaPath
Specifies the path where to find the SQL Server installation media. On this
path the SQL Server setup executable must be found.
.PARAMETER ProductKey
Specifies the product key to use for the installation, e.g. '12345-12345-12345-12345-12345'.
This parameter is mutually exclusive with the parameter Edition.
.PARAMETER EditionUpgrade
Upgrades the edition of the installed product. Requires that either the
ProductKey or the Edition parameter is also assigned. By default no edition
upgrade is performed.
.PARAMETER Edition
Specifies a free custom edition to use for the installation. This parameter
is mutually exclusive with the parameter ProductKey.
.PARAMETER LogPath
Specifies the file path where to write the log files, e.g. 'C:\Logs\Install.log'.
By default log files are created under %TEMP%.
.PARAMETER InstallFolder
Specifies the folder where to install the product, e.g. 'C:\Program Files\SSRS'.
By default the product is installed under the default installation folder.
Reporting Services: %ProgramFiles%\Microsoft SQL Server Reporting Services
PI Report Server: %ProgramFiles%\Microsoft Power BI Report Server
.PARAMETER SuppressRestart
Suppresses the restart of the computer after the installation is finished.
By default the computer is restarted after the installation is finished.
.PARAMETER Timeout
Specifies how long to wait for the setup process to finish. Default value
is `7200` seconds (2 hours). If the setup process does not finish before
this time, an exception will be thrown.
.PARAMETER Force
If specified the command will not ask for confirmation. Same as if Confirm:$false
is used.
.PARAMETER PassThru
If specified the command will return the setup process exit code.
.LINK
https://learn.microsoft.com/en-us/power-bi/report-server/install-report-server
https://learn.microsoft.com/en-us/sql/reporting-services/install-windows/install-reporting-services
.INPUTS
None.
.OUTPUTS
`System.Int32`
When PassThru is specified, returns the setup process exit code. Otherwise, no output is generated.
.EXAMPLE
Invoke-ReportServerSetupAction -Install -AcceptLicensingTerms -MediaPath 'E:\SQLServerReportingServices.exe'
Installs SQL Server Reporting Services with default settings.
.EXAMPLE
Invoke-ReportServerSetupAction -Install -AcceptLicensingTerms -MediaPath 'E:\SQLServerReportingServices.exe' -ProductKey '12345-12345-12345-12345-12345'
Installs SQL Server Reporting Services using a product key.
.EXAMPLE
Invoke-ReportServerSetupAction -Install -AcceptLicensingTerms -MediaPath 'E:\PowerBIReportServer.exe' -Edition 'Evaluation' -InstallFolder 'C:\Program Files\Power BI Report Server'
Installs Power BI Report Server in evaluation edition to a custom folder.
.EXAMPLE
Invoke-ReportServerSetupAction -Install -AcceptLicensingTerms -MediaPath 'E:\SQLServerReportingServices.exe' -ProductKey '12345-12345-12345-12345-12345' -EditionUpgrade -LogPath 'C:\Logs\SSRS_Install.log'
Installs SQL Server Reporting Services and upgrades the edition using a product key. Also specifies a custom log path.
.EXAMPLE
Invoke-ReportServerSetupAction -Repair -AcceptLicensingTerms -MediaPath 'E:\SQLServerReportingServices.exe'
Repairs an existing installation of SQL Server Reporting Services.
.EXAMPLE
Invoke-ReportServerSetupAction -Uninstall -MediaPath 'E:\SQLServerReportingServices.exe' -Force
Uninstalls SQL Server Reporting Services without prompting for confirmation.
.EXAMPLE
$exitCode = Invoke-ReportServerSetupAction -Install -AcceptLicensingTerms -MediaPath 'E:\SQLServerReportingServices.exe' -PassThru
Installs SQL Server Reporting Services and returns the setup process exit code.
#>
function Invoke-ReportServerSetupAction
{
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]
[OutputType([System.Int32])]
param
(
[Parameter(ParameterSetName = 'Install', Mandatory = $true)]
[System.Management.Automation.SwitchParameter]
$Install,
[Parameter(ParameterSetName = 'Uninstall', Mandatory = $true)]
[System.Management.Automation.SwitchParameter]
$Uninstall,
[Parameter(ParameterSetName = 'Repair', Mandatory = $true)]
[System.Management.Automation.SwitchParameter]
$Repair,
[Parameter(ParameterSetName = 'Install', Mandatory = $true)]
[Parameter(ParameterSetName = 'Repair', Mandatory = $true)]
[System.Management.Automation.SwitchParameter]
$AcceptLicensingTerms,
[Parameter(Mandatory = $true)]
[ValidateScript({
if (-not (Test-Path -Path $_ -PathType 'Leaf'))
{
throw $script:localizedData.ReportServerSetupAction_ReportServerExecutableNotFound
}
return $true
})]
[System.String]
$MediaPath,
[Parameter(ParameterSetName = 'Install')]
[Parameter(ParameterSetName = 'Repair')]
[System.String]
$ProductKey,
[Parameter(ParameterSetName = 'Install')]
[Parameter(ParameterSetName = 'Repair')]
[System.Management.Automation.SwitchParameter]
$EditionUpgrade,
[Parameter(ParameterSetName = 'Install')]
[Parameter(ParameterSetName = 'Repair')]
[ValidateSet('Developer', 'Evaluation', 'ExpressAdvanced')]
[System.String]
$Edition,
[Parameter()]
[System.String]
$LogPath,
[Parameter(ParameterSetName = 'Install')]
[Parameter(ParameterSetName = 'Repair')]
[ValidateScript({
$parentInstallFolder = Split-Path -Path $_ -Parent
if (-not (Test-Path -Path $parentInstallFolder))
{
throw $script:localizedData.ReportServerSetupAction_InstallFolderNotFound
}
return $true
})]
[System.String]
$InstallFolder,
[Parameter()]
[System.Management.Automation.SwitchParameter]
$SuppressRestart,
[Parameter()]
[System.UInt32]
$Timeout = 7200,
[Parameter()]
[System.Management.Automation.SwitchParameter]
$Force,
[Parameter()]
[System.Management.Automation.SwitchParameter]
$PassThru
)
$previousErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = 'Stop'
if ($Force.IsPresent -and -not $Confirm)
{
$ConfirmPreference = 'None'
}
$originalErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = 'Stop'
Assert-ElevatedUser -ErrorAction 'Stop'
$ErrorActionPreference = $originalErrorActionPreference
$assertBoundParameters = @{
BoundParameterList = $PSBoundParameters
MutuallyExclusiveList1 = @(
'Edition'
)
MutuallyExclusiveList2 = @(
'ProductKey'
)
}
# Either ProductKey or Edition must be specified, never both.
Assert-BoundParameter @assertBoundParameters
# If EditionUpgrade is specified then the parameter ProductKey or Edition must be specified.
$assertBoundParameters = @{
BoundParameterList = $PSBoundParameters
IfParameterPresent = @('EditionUpgrade')
RequiredParameter = ('ProductKey', 'Edition')
RequiredBehavior = 'Any'
}
Assert-BoundParameter @assertBoundParameters
$ErrorActionPreference = $previousErrorActionPreference
# Sensitive values.
$sensitiveValue = @()
# Default action is install or upgrade.
$setupArgument = '/quiet /IAcceptLicenseTerms'
if ($Uninstall.IsPresent)
{
$setupArgument += ' /uninstall'
}
elseif ($Repair.IsPresent)
{
$setupArgument += ' /repair'
}
if ($ProductKey)
{
$setupArgument += ' /PID={0}' -f $ProductKey
$sensitiveValue += @(
$ProductKey
)
}
if ($EditionUpgrade.IsPresent)
{
$setupArgument += ' /EditionUpgrade'
}
if ($Edition)
{
$editionMap = @{
Developer = 'Dev'
Evaluation = 'Eval'
ExpressAdvanced = 'ExprAdv'
}
$setupArgument += ' /Edition={0}' -f $editionMap.$Edition
}
if ($LogPath)
{
$setupArgument += ' /log "{0}"' -f $LogPath
}
if ($InstallFolder)
{
$setupArgument += ' /InstallFolder="{0}"' -f $InstallFolder
}
if ($SuppressRestart.IsPresent)
{
$setupArgument += ' /norestart'
}
$verboseSetupArgument = $setupArgument
# Obfuscate sensitive values.
foreach ($currentSensitiveValue in $sensitiveValue)
{
$escapedRegExString = [System.Text.RegularExpressions.Regex]::Escape($currentSensitiveValue)
$verboseSetupArgument = $verboseSetupArgument -replace $escapedRegExString, '********'
}
# Clear sensitive values.
$sensitiveValue = $null
Write-Verbose -Message ($script:localizedData.ReportServerSetupAction_SetupArguments -f $verboseSetupArgument)
$verboseDescriptionMessage = $script:localizedData.ReportServerSetupAction_ShouldProcessVerboseDescription -f $PSCmdlet.ParameterSetName
$verboseWarningMessage = $script:localizedData.ReportServerSetupAction_ShouldProcessVerboseWarning -f $PSCmdlet.ParameterSetName
$captionMessage = $script:localizedData.ReportServerSetupAction_ShouldProcessCaption
if ($PSCmdlet.ShouldProcess($verboseDescriptionMessage, $verboseWarningMessage, $captionMessage))
{
$expandedMediaPath = [System.Environment]::ExpandEnvironmentVariables($MediaPath)
$startProcessParameters = @{
FilePath = $expandedMediaPath
ArgumentList = $setupArgument
Timeout = $Timeout
}
# Clear setupArgument to remove any sensitive values.
$setupArgument = $null
# Run setup executable.
$processExitCode = Start-SqlSetupProcess @startProcessParameters
$setupExitMessage = ($script:localizedData.SetupAction_SetupExitMessage -f $processExitCode)
if ($processExitCode -eq 3010)
{
Write-Warning -Message (
'{0} {1}' -f $setupExitMessage, $script:localizedData.SetupAction_SetupSuccessfulRebootRequired
)
}
elseif ($processExitCode -ne 0)
{
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
$setupExitMessage,
'IRS0001', # cspell: disable-line
[System.Management.Automation.ErrorCategory]::InvalidOperation,
$PSCmdlet.ParameterSetName
)
)
}
else
{
Write-Verbose -Message (
'{0} {1}' -f $setupExitMessage, ($script:localizedData.SetupAction_SetupSuccessful)
)
}
if ($PassThru.IsPresent)
{
return $processExitCode
}
}
}