我有以下Powershell代码来还原Power报表服务器实例上的加密密钥:
$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
的本地计算机名,但仍然没有成功。
该错误似乎指的是实际模块本身的错误,而不是我的代码。有人能告诉我哪里出了问题吗?
环境
编辑:
利用这两个答案,我发现如下:
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
参数会抛出一个错误。
此页建议
+--------------------+---------+
| 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?
发布于 2020-07-01 09:45:04
错误正在从模块中抛出,但似乎是我们将数据放入模块的结果。让我们深入研究代码,看看发生了什么。
我找到了模块这里的源代码。这些向底部(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名称空间。首先,我们希望返回根的所有子名称空间。
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.
发布于 2020-07-01 09:33:38
要解决-ReportServerVersion
模块中的ReportingServicesTools
参数出现的问题,导致命名空间错误,可以使用以下三个快速步骤:
PBIRS
):Get -Class -Class __Namespace选择对象-ExpandProperty名称
输出示例: V15ReportingServicesTools
% {PSCustomObject@{Name = $_;Version = $_.value__}}
示例输出:名称版本? SQLServer2012 11 SQLServer2014 12 SQLServer2016 13 SQLServer2017 14 SQLServervNext 15。ReportingServicesTools
模块中的相应名称,并使用该名称将其传递给-ReportServerVersion
参数或直接传递整数(在去掉v
之后)。https://stackoverflow.com/questions/62516550
复制