Pipelines/Steps/Install/OnPrem/Sitecore/XP/Scaled/9.1/Install-CortexREP.ps1

$ErrorActionPreference = "Stop"

$prefix = $SAFConfiguration.prefix
$siteName = $SAFConfiguration.xConnect.cortexReportingHostName
$hostNames = @($siteName)
$license = $SAFConfiguration.license
$sqlServer = $SAFConfiguration.sql.serverName
$sqlUser = $SAFConfiguration.sql.adminUsername
$sqlAdminPassword = $SAFConfiguration.sql.adminPassword
$sqlSitecorePassword = $SAFConfiguration.sql.sitecorePassword
$installDir = $SAFConfiguration.xConnect.installDir
$environment = $SAFConfiguration.xConnect.environment
$logLevel = $SAFConfiguration.xConnect.logLevel
$package = Get-ChildItem -Path "$SAFInstallPackageDir\*" -Include *cortexreporting.scwdp.zip*
$sifConfiguration = GetSIFConfiguration -Name "xconnect-xp1-CortexReporting.json" -ContextPath "$PSScriptRoot"

$clientCert = BuildSitecoreClientCertName -Prefix $prefix
$serverCert = BuildSitecoreServerCertName -Prefix $prefix

Write-Output "Install xConnect Cortex Reporting started..."

$dbs = @("$($prefix)_Reporting")
DeleteDatabases -SqlServer $sqlServer -Databases $dbs -Username $sqlUser -Password $sqlAdminPassword

$sitecoreParams = @{
    Path = $sifConfiguration
    Package = $package.FullName
    LicenseFile = $license
    Sitename = $siteName
    SSLCert = $serverCert
    XConnectCert = $clientCert
    SqlDbPrefix = $prefix
    SqlAdminUser = $sqlUser
    SqlAdminPassword = $sqlAdminPassword
    SqlReportingUser = "$($prefix)_reportinguser"
    SqlReportingPassword = $sqlSitecorePassword
    SqlServer = $sqlServer
    XConnectEnvironment = $environment
    XConnectLogLevel = $logLevel
    InstallDirectory = $installDir
}
Install-SitecoreConfiguration @sitecoreParams
AddWebBindings -SiteName $siteName -HostNames $hostNames
AddWebBindings -SiteName $siteName -HostNames $hostNames -SSLCert $serverCert

Write-Output "Install xConnect Cortex Reporting done."