首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Powershell恢复SSRS / PowerBI报表服务器加密密钥

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

Stack Overflow用户
提问于 2020-06-22 14:18:49
回答 2查看 700关注 0票数 1

我有以下Powershell代码来还原Power报表服务器实例上的加密密钥:

代码语言:javascript
运行
复制
$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

当我运行这个程序时,我会得到一个错误:

代码语言:javascript
运行
复制
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的本地计算机名,但仍然没有成功。

该错误似乎指的是实际模块本身的错误,而不是我的代码。有人能告诉我哪里出了问题吗?

环境

编辑:

利用这两个答案,我发现如下:

代码语言:javascript
运行
复制
Restore-RsEncryptionKey -ComputerName "localhost" -Password $encKeyPass -KeyPath $encKeyPath -ReportServerInstance PBIRS -ReportServerVersion SQLServer2016

抛出

代码语言:javascript
运行
复制
Invalid namespace "root\Microsoft\SqlServer\ReportServer\RS_PBIRS\v13\Admin"

并更改-ReportServerVersion:

代码语言:javascript
运行
复制
Restore-RsEncryptionKey -ComputerName "localhost" -Password $encKeyPass -KeyPath $encKeyPath -ReportServerInstance PBIRS -ReportServerVersion SQLServer2017

抛出

代码语言:javascript
运行
复制
Invalid namespace "root\Microsoft\SqlServer\ReportServer\RS_PBIRS\v14\Admin"

(注意版本上的差异)

正在运行

代码语言:javascript
运行
复制
Get-WmiObject -Namespace "Root/Microsoft/SqlServer/ReportServer/RS_PBIRS" -Class __Namespace | Select-Object -Property Name | Sort Name

产出:

代码语言:javascript
运行
复制
Name
----
V15 

这就解释了为什么两个不同的-ReportServerVersion参数会抛出一个错误。

此页建议

代码语言:javascript
运行
复制
+--------------------+---------+
| 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返回:

代码语言:javascript
运行
复制
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?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-07-01 17:45:04

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

我找到了模块这里的源代码。这些向底部(85到102)的线向我伸出:

代码语言:javascript
运行
复制
    $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名称空间。首先,我们希望返回根的所有子名称空间。

代码语言:javascript
运行
复制
PS C:\windows\system32> Get-WmiObject -Namespace "Root" -Class __Namespace | Select-Object -Property Name | Sort Name

Name
----
Appv
cimv2
Hardware
HyperVCluster
Microsoft
WMI

既然有了这些,我们就可以继续搜索模块所期望的路径。从模块代码中我们知道,它将在下一步的名称空间/路径中点击"Microsoft“,因此将其添加到我们正在搜索的子名称空间中的名称空间中:

代码语言:javascript
运行
复制
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位报告服务器版本,因此我希望您尝试如下:

代码语言:javascript
运行
复制
Restore-RsEncryptionKey -ComputerName "localhost" -Password $encKeyPass -KeyPath $encKeyPath -ReportServerInstance PBIRS -ReportServerVersion '15'

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

代码语言:javascript
运行
复制
        .PARAMETER ReportServerVersion
            Specify the version of the SQL Server Reporting Services Instance.
            Use the "Connect-RsReportServer" function to set/update a default value.
票数 3
EN

Stack Overflow用户

发布于 2020-07-01 17:33:38

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

  1. 确定服务器支持的SQL server版本(用实际的"root\Microsoft\SqlServer\ReportServer\RS_PBIRS“(如果不同的话)替换PBIRS ):Get -Class -Class __Namespace选择对象-ExpandProperty名称 输出示例: V15
  2. 将当前版本显示为名称映射的enum::GetValues(Microsoft.ReportingServicesTools.SqlServerVersion):ReportingServicesTools% {PSCustomObject@{Name = $_;Version = $_.value__}} 示例输出:名称版本? SQLServer2012 11 SQLServer2014 12 SQLServer2016 13 SQLServer2017 14 SQLServervNext 15。
  3. 将支持的服务器版本映射到ReportingServicesTools模块中的相应名称,并使用该名称将其传递给-ReportServerVersion参数或直接传递整数(在去掉v之后)。
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62516550

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档