Skip to content

Commit 2246dcd

Browse files
authored
Invoke-ReportServerSetupAction: Add private command (#2066)
1 parent 666ef4e commit 2246dcd

File tree

8 files changed

+1156
-33
lines changed

8 files changed

+1156
-33
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55

66
## [Unreleased]
77

8+
### Added
9+
10+
- Private function:
11+
- `Invoke-ReportServerSetupAction`
12+
813
### Changed
914

1015
- SqlServerDsc
@@ -26,6 +31,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2631
- Fix localization strings in `Assert` method.
2732
- `Save-SqlDscSqlServerMediaFile`
2833
- Fix localizations strings that used wrong keys.
34+
- Fix unit tests so the work cross-platform.
35+
- `Install-SqlDscServer` and private function `Invoke-SetupAction`
36+
- Fix localization string keys naming.
37+
- Fix unit tests to use correct localization string names.
2938
- `SqlConfiguration`
3039
- Change the alias command to real command name, to pass HQRM tests.
3140
- `SqlDatabaseUser`
Lines changed: 324 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,324 @@
1+
<#
2+
.SYNOPSIS
3+
Executes setup using the provided setup executable.
4+
5+
.DESCRIPTION
6+
Executes Reporting Services or BI Report Server setup using the provided setup executable.
7+
8+
See the link in the commands help for information on each parameter.
9+
10+
.PARAMETER Install
11+
Specifies that a new installation should be performed.
12+
13+
.PARAMETER Uninstall
14+
Specifies that an uninstallation should be performed.
15+
16+
.PARAMETER Repair
17+
Specifies that a repair should be performed on an existing installation.
18+
19+
.PARAMETER AcceptLicensingTerms
20+
Required parameter to be able to run unattended install. By specifying this
21+
parameter you acknowledge the acceptance of all license terms and notices for
22+
the specified features, the terms and notices that the setup executable
23+
normally asks for.
24+
25+
.PARAMETER MediaPath
26+
Specifies the path where to find the SQL Server installation media. On this
27+
path the SQL Server setup executable must be found.
28+
29+
.PARAMETER ProductKey
30+
Specifies the product key to use for the installation, e.g. '12345-12345-12345-12345-12345'.
31+
This parameter is mutually exclusive with the parameter Edition.
32+
33+
.PARAMETER EditionUpgrade
34+
Upgrades the edition of the installed product. Requires that either the
35+
ProductKey or the Edition parameter is also assigned. By default no edition
36+
upgrade is performed.
37+
38+
.PARAMETER Edition
39+
Specifies a free custom edition to use for the installation. This parameter
40+
is mutually exclusive with the parameter ProductKey.
41+
42+
.PARAMETER LogPath
43+
Specifies the file path where to write the log files, e.g. 'C:\Logs\Install.log'.
44+
By default log files are created under %TEMP%.
45+
46+
.PARAMETER InstallFolder
47+
Specifies the folder where to install the product, e.g. 'C:\Program Files\SSRS'.
48+
By default the product is installed under the default installation folder.
49+
50+
Reporting Services: %ProgramFiles%\Microsoft SQL Server Reporting Services
51+
PI Report Server: %ProgramFiles%\Microsoft Power BI Report Server
52+
53+
.PARAMETER SuppressRestart
54+
Suppresses the restart of the computer after the installation is finished.
55+
By default the computer is restarted after the installation is finished.
56+
57+
.PARAMETER Timeout
58+
Specifies how long to wait for the setup process to finish. Default value
59+
is `7200` seconds (2 hours). If the setup process does not finish before
60+
this time, an exception will be thrown.
61+
62+
.PARAMETER Force
63+
If specified the command will not ask for confirmation. Same as if Confirm:$false
64+
is used.
65+
66+
.LINK
67+
https://learn.microsoft.com/en-us/power-bi/report-server/install-report-server
68+
https://learn.microsoft.com/en-us/sql/reporting-services/install-windows/install-reporting-services
69+
70+
.OUTPUTS
71+
None.
72+
73+
.EXAMPLE
74+
Invoke-ReportServerSetupAction -Install -AcceptLicensingTerms -MediaPath 'E:\SQLServerReportingServices.exe'
75+
76+
Installs SQL Server Reporting Services with default settings.
77+
78+
.EXAMPLE
79+
Invoke-ReportServerSetupAction -Install -AcceptLicensingTerms -MediaPath 'E:\SQLServerReportingServices.exe' -ProductKey '12345-12345-12345-12345-12345'
80+
81+
Installs SQL Server Reporting Services using a product key.
82+
83+
.EXAMPLE
84+
Invoke-ReportServerSetupAction -Install -AcceptLicensingTerms -MediaPath 'E:\PowerBIReportServer.exe' -Edition 'Evaluation' -InstallFolder 'C:\Program Files\Power BI Report Server'
85+
86+
Installs Power BI Report Server in evaluation edition to a custom folder.
87+
88+
.EXAMPLE
89+
Invoke-ReportServerSetupAction -Install -AcceptLicensingTerms -MediaPath 'E:\SQLServerReportingServices.exe' -ProductKey '12345-12345-12345-12345-12345' -EditionUpgrade -LogPath 'C:\Logs\SSRS_Install.log'
90+
91+
Installs SQL Server Reporting Services and upgrades the edition using a product key. Also specifies a custom log path.
92+
93+
.EXAMPLE
94+
Invoke-ReportServerSetupAction -Repair -AcceptLicensingTerms -MediaPath 'E:\SQLServerReportingServices.exe'
95+
96+
Repairs an existing installation of SQL Server Reporting Services.
97+
98+
.EXAMPLE
99+
Invoke-ReportServerSetupAction -Uninstall -MediaPath 'E:\SQLServerReportingServices.exe' -Force
100+
101+
Uninstalls SQL Server Reporting Services without prompting for confirmation.
102+
#>
103+
function Invoke-ReportServerSetupAction
104+
{
105+
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]
106+
[OutputType()]
107+
param
108+
(
109+
[Parameter(ParameterSetName = 'Install', Mandatory = $true)]
110+
[System.Management.Automation.SwitchParameter]
111+
$Install,
112+
113+
[Parameter(ParameterSetName = 'Uninstall', Mandatory = $true)]
114+
[System.Management.Automation.SwitchParameter]
115+
$Uninstall,
116+
117+
[Parameter(ParameterSetName = 'Repair', Mandatory = $true)]
118+
[System.Management.Automation.SwitchParameter]
119+
$Repair,
120+
121+
[Parameter(ParameterSetName = 'Install', Mandatory = $true)]
122+
[Parameter(ParameterSetName = 'Repair', Mandatory = $true)]
123+
[System.Management.Automation.SwitchParameter]
124+
$AcceptLicensingTerms,
125+
126+
[Parameter(Mandatory = $true)]
127+
[ValidateScript({
128+
if (-not (Test-Path -Path $_ -PathType 'Leaf'))
129+
{
130+
throw $script:localizedData.ReportServerSetupAction_ReportServerExecutableNotFound
131+
}
132+
133+
return $true
134+
})]
135+
[System.String]
136+
$MediaPath,
137+
138+
[Parameter(ParameterSetName = 'Install')]
139+
[Parameter(ParameterSetName = 'Repair')]
140+
[System.String]
141+
$ProductKey,
142+
143+
[Parameter(ParameterSetName = 'Install')]
144+
[Parameter(ParameterSetName = 'Repair')]
145+
[System.Management.Automation.SwitchParameter]
146+
$EditionUpgrade,
147+
148+
[Parameter(ParameterSetName = 'Install')]
149+
[Parameter(ParameterSetName = 'Repair')]
150+
[ValidateSet('Development', 'Evaluation', 'ExpressAdvanced')]
151+
[System.String]
152+
$Edition,
153+
154+
[Parameter()]
155+
[System.String]
156+
$LogPath,
157+
158+
[Parameter(ParameterSetName = 'Install')]
159+
[Parameter(ParameterSetName = 'Repair')]
160+
[ValidateScript({
161+
$parentInstallFolder = Split-Path -Path $_ -Parent
162+
163+
if (-not (Test-Path -Path $parentInstallFolder))
164+
{
165+
throw $script:localizedData.ReportServerSetupAction_InstallFolderNotFound
166+
}
167+
168+
return $true
169+
})]
170+
[System.String]
171+
$InstallFolder,
172+
173+
[Parameter()]
174+
[System.Management.Automation.SwitchParameter]
175+
$SuppressRestart,
176+
177+
[Parameter()]
178+
[System.UInt32]
179+
$Timeout = 7200,
180+
181+
[Parameter()]
182+
[System.Management.Automation.SwitchParameter]
183+
$Force
184+
)
185+
186+
if ($Force.IsPresent -and -not $Confirm)
187+
{
188+
$ConfirmPreference = 'None'
189+
}
190+
191+
Assert-ElevatedUser -ErrorAction 'Stop'
192+
193+
$assertBoundParameters = @{
194+
BoundParameterList = $PSBoundParameters
195+
MutuallyExclusiveList1 = @(
196+
'Edition'
197+
)
198+
MutuallyExclusiveList2 = @(
199+
'ProductKey'
200+
)
201+
}
202+
203+
# Either ProductKey or Edition must be specified, never both.
204+
Assert-BoundParameter @assertBoundParameters
205+
206+
# If EditionUpgrade is specified then the parameter ProductKey or Edition must be specified.
207+
$assertBoundParameters = @{
208+
BoundParameterList = $PSBoundParameters
209+
IfParameterPresent = @('EditionUpgrade')
210+
RequiredParameter = ('ProductKey', 'Edition')
211+
RequiredBehavior = 'Any'
212+
}
213+
214+
Assert-BoundParameter @assertBoundParameters
215+
216+
# Default action is install or upgrade.
217+
$setupArgument = '/quiet /IAcceptLicenseTerms'
218+
219+
if ($Uninstall.IsPresent)
220+
{
221+
$setupArgument += ' /uninstall'
222+
}
223+
elseif ($Repair.IsPresent)
224+
{
225+
$setupArgument += ' /repair'
226+
}
227+
228+
if ($ProductKey)
229+
{
230+
$setupArgument += ' /PID={0}' -f $ProductKey
231+
}
232+
233+
if ($EditionUpgrade.IsPresent)
234+
{
235+
$setupArgument += ' /EditionUpgrade'
236+
}
237+
238+
if ($Edition)
239+
{
240+
$setupArgument += ' /Edition={0}' -f $Edition
241+
}
242+
243+
if ($LogPath)
244+
{
245+
$setupArgument += ' /log "{0}"' -f $LogPath
246+
}
247+
248+
if ($InstallFolder)
249+
{
250+
$setupArgument += ' /InstallFolder="{0}"' -f $InstallFolder
251+
}
252+
253+
if ($SuppressRestart.IsPresent)
254+
{
255+
$setupArgument += ' /norestart'
256+
}
257+
258+
$verboseSetupArgument = $setupArgument
259+
260+
# Sensitive values.
261+
$sensitiveValue = @(
262+
$ProductKey
263+
)
264+
265+
# Obfuscate sensitive values.
266+
foreach ($currentSensitiveValue in $sensitiveValue)
267+
{
268+
$escapedRegExString = [System.Text.RegularExpressions.Regex]::Escape($currentSensitiveValue)
269+
270+
$verboseSetupArgument = $verboseSetupArgument -replace $escapedRegExString, '********'
271+
}
272+
273+
# Clear sensitive values.
274+
$sensitiveValue = $null
275+
276+
Write-Verbose -Message ($script:localizedData.ReportServerSetupAction_SetupArguments -f $verboseSetupArgument)
277+
278+
$verboseDescriptionMessage = $script:localizedData.ReportServerSetupAction_ShouldProcessVerboseDescription -f $PSCmdlet.ParameterSetName
279+
$verboseWarningMessage = $script:localizedData.ReportServerSetupAction_ShouldProcessVerboseWarning -f $PSCmdlet.ParameterSetName
280+
$captionMessage = $script:localizedData.ReportServerSetupAction_ShouldProcessCaption
281+
282+
if ($PSCmdlet.ShouldProcess($verboseDescriptionMessage, $verboseWarningMessage, $captionMessage))
283+
{
284+
$expandedMediaPath = [System.Environment]::ExpandEnvironmentVariables($MediaPath)
285+
286+
$startProcessParameters = @{
287+
FilePath = $expandedMediaPath
288+
ArgumentList = $setupArgument
289+
Timeout = $Timeout
290+
}
291+
292+
# Clear setupArgument to remove any sensitive values.
293+
$setupArgument = $null
294+
295+
# Run setup executable.
296+
$processExitCode = Start-SqlSetupProcess @startProcessParameters
297+
298+
$setupExitMessage = ($script:localizedData.SetupAction_SetupExitMessage -f $processExitCode)
299+
300+
if ($processExitCode -eq 3010)
301+
{
302+
Write-Warning -Message (
303+
'{0} {1}' -f $setupExitMessage, $script:localizedData.SetupAction_SetupSuccessfulRebootRequired
304+
)
305+
}
306+
elseif ($processExitCode -ne 0)
307+
{
308+
$PSCmdlet.ThrowTerminatingError(
309+
[System.Management.Automation.ErrorRecord]::new(
310+
$setupExitMessage,
311+
'IRS0001', # cspell: disable-line
312+
[System.Management.Automation.ErrorCategory]::InvalidOperation,
313+
$PSCmdlet.ParameterSetName
314+
)
315+
)
316+
}
317+
else
318+
{
319+
Write-Verbose -Message (
320+
'{0} {1}' -f $setupExitMessage, ($script:localizedData.SetupAction_SetupSuccessful)
321+
)
322+
}
323+
}
324+
}

0 commit comments

Comments
 (0)