从图像中克隆实例后,需要执行几个手动步骤才能使报表服务器正常工作。 其中包括删除所有encryption数据,包括报表服务器数据库上的对称密钥实例。
这一步需要我到RDP到有问题的服务器,打开Reporting Servicesconfigurationpipe理器并手动删除encryption的数据。
不执行这一步,当我尝试加载新服务器的报表服务器接口时,出现以下错误:
报表服务器无法打开到报表服务器数据库的连接。 所有请求和处理都需要到数据库的连接。 (rsReportServerDatabaseUnavailable)
我试图自动化这一步,以便它作为PowerShell脚本的一部分运行,以远程删除encryption的数据。
我知道'rskeymgmt -d',但是这会在运行时提示用户input,并且没有强制标志可以绕过这个额外的input,使得它不能用于远程运行,我可以看到:
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的备份报告服务器加密密钥的文章
我附上了我正在使用的完整脚本,作为我的环境克隆过程的一部分。
<# .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 (eg 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 } }