2016-07-22 65 views
1

從映像克隆實例後,需要執行幾個手動步驟才能使報表服務器正常工作。其中包括刪除所有加密數據,包括報表服務器數據庫上的對稱密鑰實例。刪除報表服務器(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)? 

回答

2

我找到了解決方案來解決這個問題。通過遠程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 
    } 
} 
1

這是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 
    } 
}