[英]Restoring SSRS / PowerBI Reporting Server encryption key using Powershell
I have the following Powershell code to restore an Encryption key on a Power BI Report Server instance:我有以下 Powershell 代码来恢复 Power BI 报表服务器实例上的加密密钥:
$encKeyPath = "C:\Test\enc.snk"
$encKeyPass = Read-Host 'Enter password for key:' -AsSecureString
Restore-RsEncryptionKey -ComputerName "localhost" -Password $encKeyPass -KeyPath $encKeyPath -ReportServerInstance PBIRS -ReportServerVersion SQLServer2016
When I run this I get the error:当我运行它时,我得到了错误:
Get-WmiObject : Invalid namespace "root\Microsoft\SqlServer\ReportServer\RS_PBIRS\v13\Admin"
At C:\Users\MyUser\Documents\WindowsPowerShell\Modules\ReportingServicesTools\ReportingServicesTools\Functions\Utilities\New-Rs
ConfigurationSettingObject.ps1:100 char:19
+ $wmiObjects = Get-WmiObject @getWmiObjectParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
I have tried also tried with the -ReportServerInstance
and -ReportServerVersion
parameters but get the same error message.我也尝试过使用-ReportServerInstance
和-ReportServerVersion
参数,但得到相同的错误消息。 I have also tried my local computer name for the -ComputerName
parameter rather than localhost
but still had no luck.我也为-ComputerName
参数而不是localhost
尝试了我的本地计算机名称,但仍然没有运气。
The error seems to refer to an error in the actual module itself rather than my code.该错误似乎是指实际模块本身而不是我的代码中的错误。 Can anyone suggest where I am going wrong?谁能建议我哪里出错了?
Environment环境
EDIT:编辑:
Using the two answers so far, I have found the following:到目前为止,使用这两个答案,我发现了以下内容:
Restore-RsEncryptionKey -ComputerName "localhost" -Password $encKeyPass -KeyPath $encKeyPath -ReportServerInstance PBIRS -ReportServerVersion SQLServer2016
Throws投掷
Invalid namespace "root\Microsoft\SqlServer\ReportServer\RS_PBIRS\v13\Admin"
and changing the -ReportServerVersion:并更改 -ReportServerVersion:
Restore-RsEncryptionKey -ComputerName "localhost" -Password $encKeyPass -KeyPath $encKeyPath -ReportServerInstance PBIRS -ReportServerVersion SQLServer2017
Throws投掷
Invalid namespace "root\Microsoft\SqlServer\ReportServer\RS_PBIRS\v14\Admin"
(note the difference in versions) (注意版本不同)
running跑步
Get-WmiObject -Namespace "Root/Microsoft/SqlServer/ReportServer/RS_PBIRS" -Class __Namespace | Select-Object -Property Name | Sort Name
outputs:输出:
Name
----
V15
which makes sense as to why the two different -ReportServerVersion
arguments throw an error.这对于为什么两个不同的-ReportServerVersion
arguments 抛出错误是有道理的。
+--------------------+---------+
| SQL Server Release | Version |
+--------------------+---------+
| SQL Server 2012 | 11 |
| SQL Server 2014 | 12 |
| SQL Server 2016 | 13 |
| SQL Server 2017 | 14 |
| SQL Server 2019 | 15 |
+--------------------+---------+
but changing -ReportServerVersion
to SQLServer2019
returns:但将-ReportServerVersion
更改为SQLServer2019
会返回:
Restore-RSEncryptionKey : Cannot process argument transformation on parameter 'ReportServerVersion'. Cannot convert value
"SQLServer2019" to type "Microsoft.ReportingServicesTools.SqlServerVersion". Error: "Unable to match the identifier name
SQLServer2019 to a valid enumerator name. Specify one of the following enumerator names and try again:
SQLServer2012, SQLServer2014, SQLServer2016, SQLServer2017, SQLServervNext"
At line:3 char:143
From here then I suppose the question is:从这里开始,我想问题是:
How do I get the module to run v15 OR how do I get version 13 of the module / namespace?如何让模块运行 v15 或如何获得模块/命名空间的第 13 版?
To troubleshoot problems with the -ReportServerVersion
parameter in the ReportingServicesTools
module, resulting in namespace errors, you can use the following three quick steps:要解决ReportingServicesTools
模块中的-ReportServerVersion
参数问题导致命名空间错误,您可以使用以下三个快速步骤:
PBIRS
by your actual ReportServerInstance, if different):确定您的服务器支持的 SQL 服务器版本(如果不同,请用您的实际 ReportServerInstance 替换PBIRS
): Get-WmiObject -Namespace "root\Microsoft\SqlServer\ReportServer\RS_PBIRS" -Class __Namespace | Select-Object -ExpandProperty Name
Example output:示例 output: V15
ReportingServicesTools
:在ReportingServicesTools
中显示当前版本以命名映射: [enum]::GetValues([Microsoft.ReportingServicesTools.SqlServerVersion]) | % {[PSCustomObject]@{Name = $_;Version = $_.value__}}
Example output:示例 output: Name Version ---- ------- SQLServer2012 11 SQLServer2014 12 SQLServer2016 13 SQLServer2017 14 SQLServervNext 15
ReportingServicesTools
module and use this name to pass it to the -ReportServerVersion
parameter or pass the integer directly (after stripping the v
). Map 您支持的服务器版本到ReportingServicesTools
模块中的相应名称,并使用此名称将其传递给-ReportServerVersion
参数或直接传递 integer (剥离v
之后)。The error is being thrown from the module, but it appears to be as a result of the data we're putting into the module.该错误是从模块中抛出的,但它似乎是我们放入模块中的数据的结果。 Let's dive into the code to see what's happening.让我们深入研究代码,看看发生了什么。
I found the source code of the module here .我在这里找到了模块的源代码。 These lines towards the bottom (85 through 102) stuck out to me:这些朝向底部的线(85 到 102)对我来说很突出:
$getWmiObjectParameters = @{
ErrorAction = "Stop"
Namespace = "root\Microsoft\SqlServer\ReportServer\RS_$ReportServerInstance\v$($ReportServerVersion.Value__)\Admin"
Class = "MSReportServer_ConfigurationSetting"
}
# code snipped
$wmiObjects = Get-WmiObject @getWmiObjectParameters
Looking back at your error, the first line is noting "invalid namespace".回顾您的错误,第一行指出“无效的命名空间”。 If anything looks immediately off in "root\Microsoft\SqlServer\ReportServer\RS_PBIRS\v13\Admin"
or your values for $ReportServerInstance
or $($ReportServerVersion.Value__)
then I'd change those.如果在"root\Microsoft\SqlServer\ReportServer\RS_PBIRS\v13\Admin"
或$ReportServerInstance
或$($ReportServerVersion.Value__)
的值中立即出现任何内容,那么我会更改它们。
If those look okay to you, I'd suggest you manually search through the available WMI namespaces on the target machine.如果这些对您来说没问题,我建议您手动搜索目标计算机上可用的 WMI 命名空间。 First, we want to return all the child namespaces of root.首先,我们要返回 root 的所有子命名空间。
PS C:\windows\system32> Get-WmiObject -Namespace "Root" -Class __Namespace | Select-Object -Property Name | Sort Name
Name
----
Appv
cimv2
Hardware
HyperVCluster
Microsoft
WMI
Now that we have those, we can continue searching down the path that the module is expecting.现在我们有了这些,我们可以继续搜索模块所期望的路径。 We know from the module code, it's expecting to hit "Microsoft" in the namespace/path next so add that to the namespace we're searching child namespaces for:我们从模块代码中知道,它预计接下来会在命名空间/路径中点击“Microsoft”,因此将其添加到我们正在搜索子命名空间的命名空间中:
PS C:\windows\system32> Get-WmiObject -Namespace "Root\Microsoft" -Class __Namespace | Select-Object -Property Name | Sort Name
Name
----
HomeNet
PolicyPlatform
protectionManagement
SecurityClient
Uev
Windows
I think if you continue down that line of logic, you'll run into the spot where the module is expecting a child WMI namespace, but the target machine lacks it.我想如果你继续沿着这条逻辑线,你会遇到模块期望子 WMI 命名空间,但目标机器缺少它的地方。
Hope this was helpful and good luck!希望这是有帮助的,祝你好运!
To answer the new question 'How do I get the module to run v15 OR how do I get version 13 of the module / namespace?'要回答新问题“如何让模块运行 v15 或如何获得模块/命名空间的第 13 版?”
The example use of the cmdlet shows use of the 2-digit report server version so I'd have you try this: cmdlet 的使用示例显示了 2 位报告服务器版本的使用,所以我让你试试这个:
Restore-RsEncryptionKey -ComputerName "localhost" -Password $encKeyPass -KeyPath $encKeyPath -ReportServerInstance PBIRS -ReportServerVersion '15'
If that returns the same error, try Connect-RsReportServer
.如果返回相同的错误,请尝试Connect-RsReportServer
。 Module documentation notes it will set/update the parameter ReportServerVersion
模块文档说明它将设置/更新参数ReportServerVersion
.PARAMETER ReportServerVersion
Specify the version of the SQL Server Reporting Services Instance.
Use the "Connect-RsReportServer" function to set/update a default value.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.