【问题标题】:Restoring SSRS / PowerBI Reporting Server encryption key using Powershell使用 Powershell 恢复 SSRS/PowerBI 报告服务器加密密钥
【发布时间】:2020-06-22 14:18:49
【问题描述】:

我有以下 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

当我运行它时,我得到了错误:

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

我也尝试过使用-ReportServerInstance-ReportServerVersion 参数,但得到相同的错误消息。我还尝试了 -ComputerName 参数而不是 localhost 的本地计算机名称,但仍然没有运气。

错误似乎是指实际模块本身的错误,而不是我的代码。谁能建议我哪里出错了?

环境

  • Power BI 报表服务器版本:1.8.7450.37410(2020 年 5 月)
  • 实例名称:PBIRS
  • 报告管理器 URL:http://localhost/reports
  • 服务网址:http://localhost/reportserver
  • ReportServer 数据库位于 SQL Server 2016 实例上(数据库名称为 PowerBIReportServer)

编辑:

到目前为止,使用这两个答案,我发现了以下内容:

Restore-RsEncryptionKey -ComputerName "localhost" -Password $encKeyPass -KeyPath $encKeyPath -ReportServerInstance PBIRS -ReportServerVersion SQLServer2016

投掷

Invalid namespace "root\Microsoft\SqlServer\ReportServer\RS_PBIRS\v13\Admin"

并更改 -ReportServerVersion:

Restore-RsEncryptionKey -ComputerName "localhost" -Password $encKeyPass -KeyPath $encKeyPath -ReportServerInstance PBIRS -ReportServerVersion SQLServer2017

投掷

Invalid namespace "root\Microsoft\SqlServer\ReportServer\RS_PBIRS\v14\Admin"

(注意版本差异)

运行

Get-WmiObject -Namespace "Root/Microsoft/SqlServer/ReportServer/RS_PBIRS" -Class __Namespace | Select-Object -Property Name | Sort Name

输出:

Name
----
V15 

这说明为什么两个不同的-ReportServerVersion 参数会引发错误。

this page 建议

+--------------------+---------+
| SQL Server Release | Version |
+--------------------+---------+
| SQL Server 2012    |      11 |
| SQL Server 2014    |      12 |
| SQL Server 2016    |      13 |
| SQL Server 2017    |      14 |
| SQL Server 2019    |      15 |
+--------------------+---------+

但将-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

从这里开始,我想问题是:

如何让模块运行 v15 或如何获得模块/命名空间的第 13 版?

【问题讨论】:

  • 你试过-ReportServerVersion SQLServervNext吗?
  • 谢谢 - 它有效!威特的建议也奏效了。你们都是对的,但我必须选择一个答案来奖励赏金,恐怕我将不得不奖励 Witt,因为他的故障排除步骤更详细

标签: powershell reporting-services powerbi sql-server-2016


【解决方案1】:

错误从模块中抛出的,但这似乎是我们将数据放入模块中的结果。让我们深入研究代码,看看发生了什么。

我找到了模块here的源代码。这些朝向底部的线(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

回顾您的错误,第一行指出“无效的命名空间”。如果 "root\Microsoft\SqlServer\ReportServer\RS_PBIRS\v13\Admin" 或您对 $ReportServerInstance$($ReportServerVersion.Value__) 的值立即显示任何内容,那么我会更改它们。

如果您觉得这些看起来不错,我建议您手动搜索目标计算机上可用的 WMI 命名空间。首先,我们要返回 root 的所有子命名空间。

PS C:\windows\system32> Get-WmiObject -Namespace "Root" -Class __Namespace | Select-Object -Property Name | Sort Name

Name
----
Appv
cimv2
Hardware
HyperVCluster
Microsoft
WMI

现在我们有了这些,我们可以继续搜索模块所期望的路径。我们从模块代码中知道,它预计接下来会在命名空间/路径中点击“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

我认为如果你继续沿着这条逻辑走下去,你会遇到模块需要一个子 WMI 命名空间,但目标机器缺少它的地方。

希望这对您有所帮助,祝您好运!

****更新:

回答新问题'如何让模块运行 v15 或如何获得模块/命名空间的第 13 版?'

cmdlet 的使用示例显示了 2 位报告服务器版本的使用,所以我想让您试试这个:

Restore-RsEncryptionKey -ComputerName "localhost" -Password $encKeyPass -KeyPath $encKeyPath -ReportServerInstance PBIRS -ReportServerVersion '15'

如果返回相同的错误,请尝试Connect-RsReportServer。模块文档说明它将设置/更新参数ReportServerVersion

        .PARAMETER ReportServerVersion
            Specify the version of the SQL Server Reporting Services Instance.
            Use the "Connect-RsReportServer" function to set/update a default value.

【讨论】:

  • 感谢您的回答。这发现了一些有趣的信息。现在修改问题以反映
  • @Searle1986 我已经更新了我的答案以回应您更新的问题。告诉我进展如何!
  • 谢谢!这行得通!它也适用于 Thomas 建议的 -ReportServerVersion SQLServervNext。
  • 由于两个答案中最深入的故障排除信息而获得赏金(尽管另一个是对我的问题的评论)
【解决方案2】:

要解决ReportingServicesTools 模块中-ReportServerVersion 参数导致命名空间错误的问题,您可以使用以下三个快速步骤:

  1. 确定您的服务器支持的 SQL Server 版本(如果不同,请将 PBIRS 替换为您的实际 ReportServerInstance):
    Get-WmiObject -Namespace "root\Microsoft\SqlServer\ReportServer\RS_PBIRS" -Class __Namespace | Select-Object -ExpandProperty Name
    
    示例输出:
    V15
    
  2. 显示当前版本以在ReportingServicesTools 中命名映射:
    [enum]::GetValues([Microsoft.ReportingServicesTools.SqlServerVersion]) | % {[PSCustomObject]@{Name = $_;Version = $_.value__}}
    
    示例输出:
              Name Version
              ---- -------
     SQLServer2012      11
     SQLServer2014      12
     SQLServer2016      13
     SQLServer2017      14
    SQLServervNext      15
    
  3. 将您支持的服务器版本映射到ReportingServicesTools 模块中的对应名称,并使用此名称将其传递给-ReportServerVersion 参数或直接传递整数(在剥离v 之后)。

【讨论】:

  • 感谢您的回复。不幸的是,它没有用,但是我现在用一些进一步的信息更新了这个问题
  • 我更新了我对 TSHOOT 快速指南的回答。对未来的读者来说可能是一个很好的总结。
猜你喜欢
  • 2014-05-19
  • 2023-04-05
  • 1970-01-01
  • 1970-01-01
  • 2019-08-13
  • 1970-01-01
  • 1970-01-01
  • 2013-10-30
  • 1970-01-01
相关资源
最近更新 更多