Backing up the Encryption Key with Powershell

Hi,

I need to automate the backup of the encryption key of SSRS with Powershell.  I tried wrapping the application rskymgmt with no success.  Then I found out that you could do it with the WMI class as mention here: http://msdn.microsoft.com/en-us/library/ms155048(v=SQL.100).aspx#CommunityContent.  How would I do that in Powershell, all my attempts have failed!

 

thx in advance.

November 17th, 2010 9:07pm

Hi Eric,

We can use the following PowerShell script to backup the encryption key:

Write-Output "Backup encryption key file"
 $serverClass = get-wmiobject -namespace "root\microsoft\sqlserver\reportserver\rs_mssqlserver\v10\admin" -class "MSReportServer_ConfigurationSetting" 
if ($serverClass -eq $null) { throw "Cannot find wmi class" }
$password = "Password01!"
$keyFile = $null
$length = 0
$HRESULT = 0
$extendedErrors = $null

$result = $serverClass.BackupEncryptionKey("Password01!")

$stream = [System.IO.File]::Create("c:\\ssrs.snk", $result.KeyFile.Length);
        
$stream.Write($result.KeyFile, 0, $result.KeyFile.Length);
        
$stream.Close();

If you have any more questions, please feel free to ask.

Thanks,
Ji

Free Windows Admin Tool Kit Click here and download it now
November 22nd, 2010 12:34pm

Hello,

I've tried this code and doesnt work :(.

February 21st, 2013 1:48am

Hi,

When I run:

$serverClass = get-wmiobject -namespace "root\microsoft\sqlserver\reportserver\rs_mssqlserver\v10\admin" -class "MSReportServer_ConfigurationSetting" 

I got a message:

get-wmiobject :
At line:1 char:16
+ $serverClass = get-wmiobject -namespace "root\microsoft\sqlserver\reportserver\r ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

What can cause this problem?

Free Windows Admin Tool Kit Click here and download it now
November 22nd, 2013 4:41am

Sorry, seems that UAC was the problem.
November 22nd, 2013 5:01am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics