简体   繁体   English

使用 Powershell 恢复 SSRS / PowerBI 报告服务器加密密钥

[英]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环境

  • Power BI Report Server version: 1.8.7450.37410 (May 2020) Power BI 报表服务器版本:1.8.7450.37410(2020 年 5 月)
  • Instance name: PBIRS实例名称:PBIRS
  • Report Manager URL: http://localhost/reports报告经理 URL:http://localhost/reports
  • Service URL: http://localhost/reportserver服务 URL:http://localhost/reportserver
  • ReportServer database is on a SQL Server 2016 instance (the database name is PowerBIReportServer) ReportServer 数据库位于 SQL Server 2016 实例上(数据库名称为 PowerBIReportServer)

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 抛出错误是有道理的。

this page suggests此页面建议

+--------------------+---------+
| 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参数问题导致命名空间错误,您可以使用以下三个快速步骤:

  1. Determine the SQL server versions your server supports (replace 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
  2. Display the current version to name mappings in 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
  3. Map your supported server version to the corresponding name in the 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!希望这是有帮助的,祝你好运!

****Update: ****更新:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM