• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 437
  • Last Modified:

Backup SSRS Encryption Keys Using Powershell

I have made the following script from google for backing up the SSRS Encryption keys:

cls
$pwd = "sa@123@123"
$SSRSClass = Get-Wmiobject -namespace "root\microsoft\sqlserver\reportserver\rs_BPSSRS\v10\admin" -class "MSReportServer_ConfigurationSetting"

$key = $SSRSClass.BackupEncryptionKey($pwd)
$stream = [System.IO.File]::Create("c:\\SSRS.snk", $key.KeyFile.Length)
$stream.Write($key.KeyFile, 0, $key.KeyFile.Length)
$stream.Close()

Open in new window


But I'm getting the following errors:

Method invocation failed because [System.Object[]] doesn't contain a method named 'BackupEn
cryptionKey'.
At line:5 char:38
+ $key = $SSRSClass.BackupEncryptionKey <<<< ($results)
    + CategoryInfo          : InvalidOperation: (BackupEncryptionKey:String) [], RuntimeEx
   ception
    + FullyQualifiedErrorId : MethodNotFound

The above code is working for the servers where there is only one named instance of SSRS is running. The above mentioned error is only thrown for servers where there are atleast two named instances are running. kindly look into this and suggest an edit asap.

Thanks
0
Eldo issac
Asked:
Eldo issac
  • 2
  • 2
1 Solution
 
Rainer JeschorCommented:
Hi,
perhaps the following Powershell command can help to determine the encoded instance names:
[code]

PS C:\windows\system32> Get-WmiObject –namespace root\Microsoft\SqlServer\ReportServer  –class __Namespace –ComputerName hostname | select Name
[/code]
From
https://msdn.microsoft.com/en-us/library/ms152836(v=sql.110).aspx

HTH
Rainer
0
 
Eldo issacAuthor Commented:
Thanks Rainer for your reply. The code given by you returns the following output:

Name
--------------
RS_BPSSRS
RS_LNTSSRSDEV

These are the two installed named instanes on the server. Kindly tell now how should I proceed. Thanks again
0
 
oBdACommented:
Try this; it will automatically determine all RS instances running on the target computer and save the file in the folder specified. The name will be the instance name, followed by a time stamp.
$ComputerName = "."
$KeyFolder = "C:\Temp"
$KeyPassword = "sa@123@123"
$TimeStamp = Get-Date -Format "-yyyyMMdd-HHmmss"

Get-WmiObject -Namespace "Root\Microsoft\SqlServer\ReportServer" -Class "__Namespace" -ComputerName $ComputerName |
	Select-Object -ExpandProperty Name |
	% {
		$KeyFileName = Join-Path -Path $KeyFolder -ChildPath ($_ + $Timestamp + ".snk")
		"Found RS instance '$($_)' on $($ComputerName); will save key to '$($KeyFileName)' ..."
		$SQLVersion = Get-WmiObject -Namespace "Root\Microsoft\SqlServer\ReportServer\$($_)" -Class "__Namespace" -ComputerName $ComputerName |
			Select-Object -ExpandProperty Name 
		$SSRSClass = Get-WmiObject -Namespace "Root\Microsoft\SqlServer\ReportServer\$($_)\$($SQLVersion)\Admin" -Class "MSReportServer_ConfigurationSetting"
		$Key = $SSRSClass.BackupEncryptionKey($KeyPassword)
		If ($Key.HRESULT -ne 0) {
			$Key.ExtendedErrors -join "`r`n" | Write-Error
		} Else {
			$Stream = [System.IO.File]::Create($KeyFileName, $Key.KeyFile.Length)
			$Stream.Write($Key.KeyFile, 0, $Key.KeyFile.Length)
			$Stream.Close()
		}
	}

Open in new window

0
 
Eldo issacAuthor Commented:
Hello oBdA,

Thanks for your reply. Your code is working perfectly fine for those servers where only one named instance is installed, but not working for those where there are more than one SSRS named instances present. I'm getting the following error:

Found RS instance 'RS_LNTSSRSDEV' on MC1-DQ820.AM.LILLY.COM; will save key to '
C:\Temp\RS_LNTSSRSDEV-20150512-014003.snk' ...
Method invocation failed because [System.Object[]] doesn't contain a method nam
ed 'BackupEncryptionKey'.
At line:15 char:40
+         $Key = $SSRSClass.BackupEncryptionKey <<<< ($KeyPassword)
    + CategoryInfo          : InvalidOperation: (BackupEncryptionKey:String) [
   ], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

Kindly look into this and give your suggestion.
0
 
oBdACommented:
Sorry:
$ComputerName = "."
$KeyFolder = "C:\Temp"
$KeyPassword = "sa@123@123"
$TimeStamp = Get-Date -Format "-yyyyMMdd-HHmmss"

Get-WmiObject -Namespace "Root\Microsoft\SqlServer\ReportServer" -Class "__Namespace" -ComputerName $ComputerName |
	Select-Object -ExpandProperty Name |
	% {
		$NameSpaceRS = $_
		$InstanceName = $NameSpaceRS.SubString(3)
		$KeyFileName = Join-Path -Path $KeyFolder -ChildPath ($InstanceName + $Timestamp + ".snk")
		"Found Reporting Services in instance '$($InstanceName)' on $($ComputerName); will save key to '$($KeyFileName)' ..."
		$SQLVersion = (Get-WmiObject -Namespace "Root\Microsoft\SqlServer\ReportServer\$($NameSpaceRS)" -Class "__Namespace" -ComputerName $ComputerName).Name
		$SSRSClass = Get-WmiObject -Namespace "Root\Microsoft\SqlServer\ReportServer\$($NameSpaceRS)\$($SQLVersion)\Admin" -Query "SELECT * FROM MSReportServer_ConfigurationSetting WHERE InstanceName='$($InstanceName)'" -ComputerName $ComputerName
		$Key = $SSRSClass.BackupEncryptionKey($KeyPassword)
		If ($Key.HRESULT -ne 0) {
			$Key.ExtendedErrors -join "`r`n" | Write-Error
		} Else {
			$Stream = [System.IO.File]::Create($KeyFileName, $Key.KeyFile.Length)
			$Stream.Write($Key.KeyFile, 0, $Key.KeyFile.Length)
			$Stream.Close()
		}
	}

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

WEBINAR: 10 Easy Ways to Lose a Password

Join us on June 27th at 8 am PDT to learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees. We'll cover the importance of multi-factor authentication and how these solutions can better protect your business!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now