2

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()

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

Exception calling "Create" with "2" argument(s): "Positive number required.
Parameter name: bufferSize"
At line:6 char:35
+ $stream = [System.IO.File]::Create <<<< ("c:\\SSRS.snk", $key.KeyFile.Length)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

You cannot call a method on a null-valued expression.
At line:7 char:14
+ $stream.Write <<<< ($key.KeyFile, 0, $key.KeyFile.Length)
    + CategoryInfo          : InvalidOperation: (Write:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At line:8 char:14
+ $stream.Close <<<< ()
    + CategoryInfo          : InvalidOperation: (Close:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

I'm using powershell v2. I tried finding about this but no luck. There are around 50+ SSRS servers in our environment and doing backup manually is tiresome. Hence, we came up with this automation. Kindly provide your comments.

Thanks

1 Answer 1

2

Using WMI to backup RS key might not be so efficient. You may try the below script that I found at http://powershell-tips.blogspot.com/2015/05/backup-report-server-encryption-key.html

#------------------------------------------------------------------------------------------
#     Script : Backup_RSKey.ps1 
#     Author : Som DT.
#    Purpose : Backup Report Server Encryption Key with Powershell
#------------------------------------------------------------------------------------------
#     Syntax : Powershell .\Backup_RSKey.ps1 -InstanceName <InstanceName> -PassWord <Password> -BackupLocation <BackupLocation> 
#------------------------------------------------------------------------------------------
#    Example : Powershell .\Backup_RSKey.ps1 -InstanceName "MSSQLSERVER" -PassWord "rsdal@2015" -BackupLocation "C:\temp"
#------------------------------------------------------------------------------------------

param ( 
    [string]$InstanceName="MSSQLSERVER", 
    [string]$PassWord="rsdal@2015", 
    [string]$BackupLocation="C:\temps" 
)

cls
$FileTimestamp=$(get-date).tostring("yyyyMMddHHmmss")


function Backup-RSKey([string]$InstanceName , [string]$PassWord, [string]$BackupLocation)
{
    Trap {
        echo  "Failure : $($Error[0].Exception.Message)" 
        return 
    }

    $KeyFile="${BackupLocation}\KEY_$InstanceName_$FileTimestamp.snk" 

    echo "Backing up to file : $KeyFile" 

    $Error.Clear() 

    Out-String -InputObject( echo "Y" | RSKeyMgmt.exe -e -f"$KeyFile" -p"$PasWord" -i"$InstanceName")  

    if (!(Test-Path "$KeyFile") )
    {
        return "Failure : Error occured while backing up [$KeyFile]."
    }
    else 
    {
        return "Success"
    }

}


$Output=Backup-RSKey "$InstanceName"  "$PassWord"   "$BackupLocation"

echo $Output

#--------------------------------------------------------------------------------------------------------------
#-- End of Program
#--------------------------------------------------------------------------------------------------------------
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.