Skip to content

Commit 0c459a8

Browse files
author
FriedrichWeinmann
committed
Formatting Guidelines compliance
Formatting Guidelines compliance, fixed a few issues.
1 parent f588622 commit 0c459a8

13 files changed

+483
-470
lines changed

Functions/Admin/Backup-RsEncryptionKey.ps1

Lines changed: 84 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44
function Backup-RsEncryptionKey
55
{
66
<#
7-
.SYNOPSIS
8-
This script creates a back up of the SQL Server Reporting Services encryption key.
9-
10-
.DESCRIPTION
11-
This script creates a back up of the encryption key for SQL Server Reporting Services. This key is needed in order to read all the encrypted content stored in the Reporting Services Catalog database.
12-
13-
.PARAMETER ReportServerInstance
7+
.SYNOPSIS
8+
This script creates a back up of the SQL Server Reporting Services encryption key.
9+
10+
.DESCRIPTION
11+
This script creates a back up of the encryption key for SQL Server Reporting Services. This key is needed in order to read all the encrypted content stored in the Reporting Services Catalog database.
12+
13+
.PARAMETER Password
14+
Specify the password to be used for backing up the encryption key. This password will be required when restoring the encryption key.
15+
16+
.PARAMETER KeyPath
17+
Specify the path to where the encryption key should be stored.
18+
19+
.PARAMETER ReportServerInstance
1420
Specify the name of the SQL Server Reporting Services Instance.
1521
Use the "Connect-RsReportServer" function to set/update a default value.
1622
@@ -25,46 +31,55 @@ function Backup-RsEncryptionKey
2531
.PARAMETER Credential
2632
The credentials with which to connect to the Report Server.
2733
Use the "Connect-RsReportServer" function to set/update a default value.
28-
29-
.PARAMETER Password
30-
Specify the password to be used for backing up the encryption key. This password will be required when restoring the encryption key.
31-
32-
.PARAMETER KeyPath
33-
Specify the path to where the encryption key should be stored.
34-
35-
.EXAMPLE
36-
Backup-RSEncryptionKey -Password 'Enter Your Password' -KeyPath 'C:\ReportingServices\Default.snk'
37-
Description
38-
-----------
39-
This command will back up the encryption key against default instance from SQL Server 2016 Reporting Services
40-
41-
.EXAMPLE
42-
Backup-RSEncryptionKey -ReportServerInstance 'SQL2012' -ReportServerVersion '11' -Password 'Enter Your Password' -KeyPath 'C:\ReportingServices\Default.snk'
43-
Description
44-
-----------
45-
This command will back up the encryption key against named instance (SQL2012) from SQL Server 2012 Reporting Services
46-
47-
.NOTES
48-
Author: ???
49-
Editors: Friedrich Weinmann
50-
Created on: ???
51-
Last Change: 31.01.2017
52-
Version: 1.1
53-
54-
Release 1.1 (26.01.2017, Friedrich Weinmann)
55-
- Fixed Parameter help (Don't poison the name with "(optional)", breaks Get-Help)
56-
- Implemented ShouldProcess (-WhatIf, -Confirm)
57-
- Replaced calling exit with throwing a terminating error (exit is a bit of an overkill when failing a simple execution)
58-
- Improved error message on failure.
59-
- Standardized the parameters governing the Report Server connection for consistent user experience.
60-
61-
Release 1.0 (???, ???)
62-
- Initial Release
34+
35+
.EXAMPLE
36+
Backup-RSEncryptionKey -Password 'Enter Your Password' -KeyPath 'C:\ReportingServices\Default.snk'
37+
Description
38+
-----------
39+
This command will back up the encryption key against default instance from SQL Server 2016 Reporting Services
40+
41+
.EXAMPLE
42+
Backup-RSEncryptionKey -ReportServerInstance 'SQL2012' -ReportServerVersion '11' -Password 'Enter Your Password' -KeyPath 'C:\ReportingServices\Default.snk'
43+
Description
44+
-----------
45+
This command will back up the encryption key against named instance (SQL2012) from SQL Server 2012 Reporting Services
46+
47+
.EXAMPLE
48+
Backup-RSEncryptionKey -ComputerName "sql2012a243" -Credential (Get-Credential) -ReportServerInstance 'SQL2012' -ReportServerVersion 'SQLServer2012' -Password 'Enter Your Password' -KeyPath 'C:\ReportingServices\Default.snk'
49+
Description
50+
-----------
51+
This command will back up the encryption key against named instance (SQL2012) from SQL Server 2012 Reporting Services.
52+
To do so, it will not use the default connection, but rather connect to the computer "sql2012a243", prompting the user for connection credentials.
53+
54+
.NOTES
55+
Author: ???
56+
Editors: Friedrich Weinmann
57+
Created on: ???
58+
Last Change: 31.01.2017
59+
Version: 1.1
60+
61+
Release 1.1 (26.01.2017, Friedrich Weinmann)
62+
- Fixed Parameter help (Don't poison the name with "(optional)", breaks Get-Help)
63+
- Implemented ShouldProcess (-WhatIf, -Confirm)
64+
- Replaced calling exit with throwing a terminating error (exit is a bit of an overkill when failing a simple execution)
65+
- Improved error message on failure.
66+
- Standardized the parameters governing the Report Server connection for consistent user experience.
67+
68+
Release 1.0 (???, ???)
69+
- Initial Release
6370
#>
6471

6572
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
6673
param
6774
(
75+
[Parameter(Mandatory = $True)]
76+
[string]
77+
$Password,
78+
79+
[Parameter(Mandatory = $True)]
80+
[string]
81+
$KeyPath,
82+
6883
[Alias('SqlServerInstance')]
6984
[string]
7085
$ReportServerInstance,
@@ -77,61 +92,53 @@ function Backup-RsEncryptionKey
7792
$ComputerName,
7893

7994
[System.Management.Automation.PSCredential]
80-
$Credential,
81-
82-
[Parameter(Mandatory = $True)]
83-
[string]
84-
$Password,
85-
86-
[Parameter(Mandatory = $True)]
87-
[string]
88-
$KeyPath
89-
)
95+
$Credential
96+
)
9097

9198
if ($ComputerName) { $tempComputerName = $ComputerName }
9299
else { $tempComputerName = ([ReportingServicesTools.ConnectionHost]::ComputerName) }
93100
if ($ReportServerInstance) { $tempInstanceName = $ReportServerInstance }
94101
else { $tempInstanceName = ([ReportingServicesTools.ConnectionHost]::Instance) }
95102

96103
if ($PSCmdlet.ShouldProcess("$tempComputerName \ $tempInstanceName", "Retrieve encryption key and create backup in $KeyPath"))
97-
{
98-
#region Connect to Report Server using WMI
104+
{
105+
#region Connect to Report Server using WMI
99106
try
100107
{
101108
$splat = @{ }
102109
if ($PSBoundParameters.ContainsKey('ReportServerInstance')) { $splat['ReportServerInstance'] = $ReportServerInstance }
103110
if ($PSBoundParameters.ContainsKey('ReportServerVersion')) { $splat['ReportServerVersion'] = $ReportServerVersion }
104111
if ($PSBoundParameters.ContainsKey('ComputerName')) { $splat['ComputerName'] = $ComputerName }
105112
if ($PSBoundParameters.ContainsKey('Credential')) { $splat['Credential'] = $Credential }
106-
$wmi = New-RsConfigurationSettingObject @splat
113+
$rsWmiObject = New-RsConfigurationSettingObject @splat
107114
}
108115
catch
109116
{
110117
throw
111118
}
112119
#endregion Connect to Report Server using WMI
113-
114-
Write-Verbose "Retrieving encryption key..."
115-
$encryptionKeyResult = $wmi.BackupEncryptionKey($Password)
116-
117-
if ($encryptionKeyResult.HRESULT -eq 0)
118-
{
120+
121+
Write-Verbose "Retrieving encryption key..."
122+
$encryptionKeyResult = $rsWmiObject.BackupEncryptionKey($Password)
123+
124+
if ($encryptionKeyResult.HRESULT -eq 0)
125+
{
119126
Write-Verbose "Retrieving encryption key... Success!"
120-
}
121-
else
122-
{
123-
throw "Failed to create backup of the encryption key. Errors: $($encryptionKeyResult.ExtendedErrors)"
124-
}
125-
126-
try
127-
{
128-
Write-Verbose "Writing key to file..."
129-
[System.IO.File]::WriteAllBytes($KeyPath, $encryptionKeyResult.KeyFile)
127+
}
128+
else
129+
{
130+
throw "Failed to create backup of the encryption key. Errors: $($encryptionKeyResult.ExtendedErrors)"
131+
}
132+
133+
try
134+
{
135+
Write-Verbose "Writing key to file..."
136+
[System.IO.File]::WriteAllBytes($KeyPath, $encryptionKeyResult.KeyFile)
130137
Write-Verbose "Writing key to file... Success!"
131-
}
132-
catch
133-
{
134-
throw
135-
}
136-
}
138+
}
139+
catch
140+
{
141+
throw
142+
}
143+
}
137144
}

Functions/Admin/Register-RsPowerBI.ps1

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function Register-RsPowerBI
5858
Use the "Connect-RsReportServer" function to set/update a default value.
5959
6060
.EXAMPLE
61-
PS C:\> Register-RsPowerBI -ClientId 'value1' -ClientSecret 'value2' -AppObjectId 'value3' -TenantName 'value4' -TenantId 'value5' -RedirectUrls 'value6'
61+
Register-RsPowerBI -ClientId 'value1' -ClientSecret 'value2' -AppObjectId 'value3' -TenantName 'value4' -TenantId 'value5' -RedirectUrls 'value6'
6262
6363
<Insert description here>
6464
@@ -134,11 +134,16 @@ function Register-RsPowerBI
134134

135135
[System.Management.Automation.PSCredential]
136136
$Credential
137-
)
138-
139-
if ($PSCmdlet.ShouldProcess($ReportServerInstance, "Registering PowerBI for SQL Server Instance"))
140-
{
141-
#region Connect to Report Server using WMI
137+
)
138+
139+
if ($ComputerName) { $tempComputerName = $ComputerName }
140+
else { $tempComputerName = ([ReportingServicesTools.ConnectionHost]::ComputerName) }
141+
if ($ReportServerInstance) { $tempInstanceName = $ReportServerInstance }
142+
else { $tempInstanceName = ([ReportingServicesTools.ConnectionHost]::Instance) }
143+
144+
if ($PSCmdlet.ShouldProcess("$tempComputerName \ $tempInstanceName", "Registering PowerBI for SQL Server Instance"))
145+
{
146+
#region Connect to Report Server using WMI
142147
try
143148
{
144149
$splat = @{ }
@@ -154,25 +159,25 @@ function Register-RsPowerBI
154159
}
155160
#endregion Connect to Report Server using WMI
156161

157-
Write-Verbose "Configuring Power BI ..."
158-
$configureResult = $rsWmiObject.SavePowerBIInformation($ClientId,
159-
$ClientSecret,
160-
$AppObjectId,
161-
$TenantName,
162-
$TenantId,
163-
$ResourceUrl,
164-
$AuthUrl,
165-
$TokenUrl,
166-
$RedirectUrls)
167-
168-
if ($configureResult.HRESULT -eq 0)
169-
{
162+
Write-Verbose "Configuring Power BI ..."
163+
$configureResult = $rsWmiObject.SavePowerBIInformation($ClientId,
164+
$ClientSecret,
165+
$AppObjectId,
166+
$TenantName,
167+
$TenantId,
168+
$ResourceUrl,
169+
$AuthUrl,
170+
$TokenUrl,
171+
$RedirectUrls)
172+
173+
if ($configureResult.HRESULT -eq 0)
174+
{
170175
Write-Verbose "Configuring Power BI ... Success!"
171-
}
172-
else
173-
{
174-
throw "Failed to register PowerBI for server instance: $ReportServerInstance. Errors: $($configureResult.ExtendedErrors)"
175-
}
176-
}
176+
}
177+
else
178+
{
179+
throw "Failed to register PowerBI for server instance: $ReportServerInstance. Errors: $($configureResult.ExtendedErrors)"
180+
}
181+
}
177182
}
178-
New-Alias -Name "Register-PowerBI" -Value "Register-RsPowerBI" -Scope Global
183+
New-Alias -Name "Register-PowerBI" -Value "Register-RsPowerBI" -Scope Global

0 commit comments

Comments
 (0)