Pipelines/Steps/Install/OnPrem/Sitecore/Configure-AppPoolAccessToPerformanceMonitoring.ps1

$ErrorActionPreference = "Stop"

Write-Output "Configure AppPool access to performance monitoring started..."

$pools = @()

if ($null -ne $SAFConfiguration.sitecore.hostNames) {
    $pools += $SAFConfiguration.sitecore.hostNames[0]
}

if ($null -ne $SAFConfiguration.xConnect.hostName) {
    $pools += $SAFConfiguration.xConnect.hostName
}

if ($null -ne $SAFConfiguration.processing.hostName) {
    $pools += $SAFConfiguration.processing.hostName
}

if ($null -ne $SAFConfiguration.reporting.hostName) {
    $pools += $SAFConfiguration.reporting.hostName
}

if ($null -ne $SAFConfiguration.xConnect.collectionHostName) {
    $pools += $SAFConfiguration.xConnect.collectionHostName
}

if ($null -ne $SAFConfiguration.xConnect.collectionSearchHostName) {
    $pools += $SAFConfiguration.xConnect.collectionSearchHostName
}

if ($null -ne $SAFConfiguration.xDB.automationOperationsHostName) {
    $pools += $SAFConfiguration.xDB.automationOperationsHostName
}

if ($null -ne $SAFConfiguration.xDB.automationReportingHostName) {
    $pools += $SAFConfiguration.xDB.automationReportingHostName
}

if ($null -ne $SAFConfiguration.xDB.referenceDataHostName) {
    $pools += $SAFConfiguration.xDB.referenceDataHostName
}

if ($null -ne $SAFConfiguration.identityServer.hostName) {
    $pools += $SAFConfiguration.identityServer.hostName
}

$groups = @("Performance Log Users", "Performance Monitor Users")
AddAppPoolUserToGroups -AppPools $pools -Groups $groups

Write-Output "Configure AppPool access to performance monitoring done."