删除报表服务器(2014本机模式)加密密钥和数据[PowerShell]

问题描述:

从映像克隆实例后,需要执行几个手动步骤才能使报表服务器正常工作。其中包括删除所有加密数据,包括报表服务器数据库上的对称密钥实例。删除报表服务器(2014本机模式)加密密钥和数据[PowerShell]

此步骤需要我将RDP发送到相关服务器,打开Reporting Services配置管理器并手动删除加密数据。

不进行这一步,我得到以下错误,当我尝试加载了新服务器的报告服务器接口:

报表服务器无法打开与报表服务器 数据库的连接。所有请求 和处理都需要到数据库的连接。 (rsReportServerDatabaseUnavailable)

我试图自动执行此步骤,以便它作为PowerShell脚本的一部分运行以远程删除加密数据。

我所知道的“rskeymgmt -d”但这种提示输入用户运行时,有没有可用来规避这种额外的输入力的标志,而不能使用的,据我可以看到远程运行:

C:\>rskeymgmt -d 
All data will be lost. Are you sure you want to delete all encrypted data from 
the report server database (Y/N)? 

我找到了解决方案来解决这个问题。通过远程PowerShell会话调用RSKeyMgmt -d,并将Y字符串传递给调用传递RSKeyMgmt提示用户输入的参数。此方法基于Som DT's post on backing up report server encryption keys

我附加了我用作环境克隆过程一部分的完整脚本。

<# 
.SYNOPSIS 
    Deletes encrypted content from a report server 

.PARAMETER MachineName 
    The name of the machine that the report server resides on 

.EXAMPLE 
    ./Delete-EncryptedSsrsContent.ps1 -MachineName 'dev41pc123' 
    Deletes encrypted content from the 'dev41pc123' report server 
#> 

param([string]$MachineName = $(throw "MachineName parameter required, for command line usage of this script, type: 'get-help ./Delete-EncryptedSSRS.ps1 -examples'")) 

trap [SystemException]{Write-Output "`n`nERROR: $_";exit 1} 
Set-StrictMode -Version Latest 

try 
{ 
    Write-Output "`nCreating remote session to the '$machineName' machine now..." 
    $session = New-PSsession -Computername $machineName 
    Invoke-Command -Session $Session -ScriptBlock {"Y" | RSKeyMgmt -d} 
} 
catch 
{ 
    Write-Output "`n`nERROR: $_" 
} 
finally 
{ 
    if ($Session) 
    { 
     Remove-PSSession $Session 
    } 
} 

这是ShaneC的溶液的推广,以支持对非默认实例的加密内容删除:

<# 
.SYNOPSIS 
    Deletes encrypted content from a report server 

.PARAMETER MachineName 
    The name of the machine that the report server resides on 

.EXAMPLE 
    ./Delete-EncryptedSsrsContent.ps1 -MachineName 'dev41pc123' 
    Deletes encrypted content from the default instance (MSSQLSERVER) of the 'dev41pc123' report server 

.EXAMPLE 
    ./Delete-EncryptedSsrsContent.ps1 -MachineName 'dev41pc123' -InstanceName 'NonDefault' 
    Deletes encrypted content from the specified non-default instance (e.g. NonDefault) of the 'dev41pc123' report server 
#> 

param(
    [Parameter(Mandatory=$true)] 
    [string]$MachineName = $(throw "MachineName parameter required, for command line usage of this script, type: 'get-help ./Delete-EncryptedSSRS.ps1 -examples'"), 

    [Parameter(Mandatory=$false)] 
    [string]$InstanceName) 

trap [SystemException]{Write-Output "`n`nERROR: $_";exit 1} 
Set-StrictMode -Version Latest 

try 
{ 
    Write-Output "`nCreating remote session to the '$MachineName' machine now..." 
    $session = New-PSsession -Computername $MachineName 
    if ([string]::IsNullOrEmpty($instanceName)) 
    { 
     Invoke-Command -Session $Session -ScriptBlock {"Y" | RSKeyMgmt.exe -d} 
    } 
    else 
    { 
     Write-Output "`nDeleting all encrypted content from the $InstanceName instance on the $MachineName machine now...`n" 
     $command = """Y""| RSKeyMgmt.exe -d -i""" + $InstanceName + """" 
     Invoke-Command -Session $Session -ScriptBlock { Invoke-Expression $args[0] } -ArgumentList $command 
     Write-Output "`n" 
    } 
} 
catch 
{ 
    Write-Output "`n`nERROR: $_" 
} 
finally 
{ 
    if ($Session) 
    { 
     Remove-PSSession $Session 
    } 
}