SE1986
SE1986

Reputation: 2760

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:

$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. I have also tried my local computer name for the -ComputerName parameter rather than localhost but still had no luck.

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:

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.

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:

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?

Upvotes: 1

Views: 1544

Answers (2)

stackprotector
stackprotector

Reputation: 13588

To troubleshoot problems with the -ReportServerVersion parameter in the ReportingServicesTools module, resulting in namespace errors, you can use the following three quick steps:

  1. Determine the SQL server versions your server supports (replace PBIRS by your actual ReportServerInstance, if different):
    Get-WmiObject -Namespace "root\Microsoft\SqlServer\ReportServer\RS_PBIRS" -Class __Namespace | Select-Object -ExpandProperty Name
    
    Example output:
    V15
    
  2. Display the current version to name mappings in ReportingServicesTools:
    [enum]::GetValues([Microsoft.ReportingServicesTools.SqlServerVersion]) | % {[PSCustomObject]@{Name = $_;Version = $_.value__}}
    
    Example 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).

Upvotes: 3

Witt
Witt

Reputation: 679

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:

    $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.

If those look okay to you, I'd suggest you manually search through the available WMI namespaces on the target machine. First, we want to return all the child namespaces of 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:

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.

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?'

The example use of the cmdlet shows use of the 2-digit report server version so I'd have you try this:

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

If that returns the same error, try Connect-RsReportServer. Module documentation notes it will set/update the parameter ReportServerVersion

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

Upvotes: 3

Related Questions