自动安装和配置SQL Server 2017 Reporting Services

时间:2018-01-02 20:35:44

标签: powershell reporting-services automation

我正在尝试静默安装和配置SQL Server 2017 Reporting Services。静默安装很简单,我使用下面的PowerShell脚本完成了大部分配置。

我遇到问题的地方是尝试设置报表管理器的虚拟目录。我在下一行收到错误

$configset.SetVirtualDirectory("ReportManager", "Reports", 1033)
  

HRESULT -2147220938:找不到应用程序。

How to automate SSRS install and configuration,我似乎按正确的顺序执行了这些步骤。

$configset = Get-WmiObject –namespace "root\Microsoft\SqlServer\ReportServer\RS_SSRS\v14\Admin" `
    -class MSReportServer_ConfigurationSetting -ComputerName localhost

$configset

If (! $configset.IsInitialized)
{
    [string]$dbscript = $configset.GenerateDatabaseCreationScript("ReportServer", 1033, $false).Script

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
    Import-Module sqlps -DisableNameChecking | Out-Null

    $conn = New-Object Microsoft.SqlServer.Management.Common.ServerConnection -ArgumentList $env:ComputerName
    $conn.ApplicationName = "Script"
    $conn.StatementTimeout = 0
    $conn.Connect()
    $smo = New-Object Microsoft.SqlServer.Management.Smo.Server -ArgumentList $conn

    # Create the ReportServer and ReportServerTempDB databases
    $db = $smo.Databases["master"]
    $db.ExecuteNonQuery($dbscript)

    # Set permissions for the databases
    $dbscript = $configset.GenerateDatabaseRightsScript($configset.WindowsServiceIdentityConfigured, "ReportServer", $false, $true).Script
    $db.ExecuteNonQuery($dbscript)

    # Set the database connection info
    $configset.SetDatabaseConnection("(local)", "ReportServer", 2, "", "")

    $configset.SetVirtualDirectory("ReportServerWebService", "ReportServer", 1033)
    $configset.ReserveURL("ReportServerWebService", "http://+:80", 1033)

    $configset.SetVirtualDirectory("ReportManager", "Reports", 1033)
    $configset.ReserveURL("ReportManager", "http://+:80", 1033)

    $configset.InitializeReportServer($configset.InstallationID)

    $configset.IsReportManagerEnabled
    $configset.IsInitialized
    $configset.IsWebServiceEnabled
    $configset.IsWindowsServiceEnabled
    $configset.ListReportServersInDatabase()
    $configset.ListReservedUrls();

    $inst = Get-WmiObject –namespace "root\Microsoft\SqlServer\ReportServer\RS_SSRS\v14" `
        -class MSReportServer_Instance -ComputerName localhost

    $inst.GetReportServerUrls()
}

对此问题的任何见解表示赞赏!

2 个答案:

答案 0 :(得分:1)

您可以使用DSC此链接应该包含有关如何使用dsc资源的信息:

https://docs.microsoft.com/en-us/sql/database-engine/install-windows/install-sql-server-on-server-core

当这段代码是Xrev时,我能够使用当时名为MSFT_xSQLServerSetup的资源安装和配置SSRS。

以下是设置单个sql server的示例。 https://github.com/PowerShell/SqlServerDsc/blob/master/Examples/SQL-Standalone.ps1

答案 1 :(得分:0)

问题出在SQL Server 2016(及更高版本)上,报表管理器的Web应用程序名称已从ReportManager更改为ReportServerWebApp