Pipelines/Steps/Install/OnPrem/Sitecore/XP/AllInOne/9.2/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)_ProcessingEngineStorage", "$($prefix)_ProcessingEngineTasks", "$($prefix)_ReferenceData", "$($prefix)_Reporting", "$($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
    XConnectCert = $clientCert
    SqlDbPrefix = $prefix
    SolrCorePrefix = $prefix
    SSLCert = $serverCert
    SqlAdminUser = $sqlUser
    SqlAdminPassword = $sqlAdminPassword
    SolrURL = $SAFSolrServiceURL
    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
    SqlProcessingEngineUser = "$($prefix)_processingengineuser"
    SqlProcessingEnginePassword = $sqlSitecorePassword
    SqlReportingUser = "$($prefix)_reportinguser"
    SqlReportingPassword = $sqlSitecorePassword
    SqlServer = $sqlServer
    MachineLearningServerUrl = $SAFConfiguration.xConnect.machineLearningServer.url
    MachineLearningServerBlobEndpointCertificatePath = $SAFConfiguration.xConnect.machineLearningServer.blobEndpointCertificatePath
    MachineLearningServerBlobEndpointCertificatePassword = $SAFConfiguration.xConnect.machineLearningServer.blobEndpointCertificatePassword
    MachineLearningServerTableEndpointCertificatePath = $SAFConfiguration.xConnect.machineLearningServer.tableEndpointCertificatePath
    MachineLearningServerTableEndpointCertificatePassword = $SAFConfiguration.xConnect.machineLearningServer.tableEndpointCertificatePassword
    MachineLearningServerEndpointCertificationAuthorityCertificatePath = $SAFConfiguration.xConnect.machineLearningServer.endpointCertificationAuthorityCertificatePath
    InstallDirectory = $installDir
}
Install-SitecoreConfiguration @xconnectParams
AddWebBindings -SiteName $siteName -HostNames $hostNames
AddWebBindings -SiteName $siteName -HostNames $hostNames -SSLCert $serverCert

Write-Output "Install xConnect done."