Pipelines/Steps/Install/OnPrem/Sitecore/XP/AllInOne/9.0/Install-XConnect.ps1

$ErrorActionPreference = "Stop"

Write-Output "Install xConnect started..."

$prefix = $SAFConfiguration.prefix
$xConnectHostName = $SAFConfiguration.xConnect.hostName
$hostNames = @($xConnectHostName)
$siteName = $hostNames[0]
$license = $SAFConfiguration.license
$sqlServer = $SAFConfiguration.sql.serverName
$sqlUser =  $SAFConfiguration.sql.adminUsername
$sqlAdminPassword =  $SAFConfiguration.sql.adminPassword
$sqlSitecorePassword = $SAFConfiguration.sql.sitecorePassword
$installDir = $SAFConfiguration.xConnect.installDir
$package = Get-ChildItem -Path "$SAFInstallPackageDir\*" -Include *xconnect.scwdp.zip*
$sifConfiguration = GetSIFConfiguration -Name "xconnect-xp0.json" -ContextPath "$PSScriptRoot"

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

$dbs = @("$($prefix)_MarketingAutomation", "$($prefix)_Messaging", "$($prefix)_Processing.Pools", "$($prefix)_ReferenceData", "$($prefix)_Xdb.Collection.Shard0", "$($prefix)_Xdb.Collection.Shard1", "$($prefix)_Xdb.Collection.ShardMapManager")
DeleteDatabases -SqlServer $sqlServer -Databases $dbs -Username $sqlUser -Password $sqlAdminPassword
DeleteLogin -SqlServer $sqlServer -SqlLogin "$($prefix)_collectionuser" -Username $sqlUser -Password $sqlAdminPassword

$xconnectParams = @{
    Path                           = $sifConfiguration
    Package                        = $package.FullName
    LicenseFile                    = $license
    Sitename                       = $xConnectHostName
    SSLCert                        = $serverCert
    XConnectCert                   = $clientCert
    SqlDbPrefix                    = $prefix
    SqlServer                      = $sqlServer
    SqlAdminUser                   = $sqlUser
    SqlAdminPassword               = $sqlAdminPassword
    SqlCollectionUser              = "$($prefix)_collectionuser"
    SqlCollectionPassword          = $sqlSitecorePassword
    SqlProcessingPoolsUser         = "$($prefix)_processingpoolsuser"
    SqlProcessingPoolsPassword     = $sqlSitecorePassword
    SqlReferenceDataUser           = "$($prefix)_referencedatauser"
    SqlReferenceDataPassword       = $sqlSitecorePassword
    SqlMarketingAutomationUser     = "$($prefix)_marketingautomationuser"
    SqlMarketingAutomationPassword = $sqlSitecorePassword
    SqlMessagingUser               = "$($prefix)_messaginguser"
    SqlMessagingPassword           = $sqlSitecorePassword
    SolrCorePrefix                 = $prefix
    SolrURL                        = $SAFSolrServiceURL
    InstallDirectory               = $installDir
}
Install-SitecoreConfiguration @xconnectParams
AddWebBindings -SiteName $siteName -HostNames $hostNames
AddWebBindings -SiteName $siteName -HostNames $hostNames -SSLCert $serverCert

Write-Output "Install xConnect done."