ps/Modules/Alkami.PowerShell.IIS/Public/Set-ApplicationPoolExecutionAccount.ps1

40 lines
1.1 KiB
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function Set-ApplicationPoolExecutionAccount {
<#
.SYNOPSIS
Sets the Execution Account for an Application Pool
.PARAMETER AppPool
[string] The web application pool.
.PARAMETER Credential
[PSCredential] The credentials to use for configuration here
.PARAMETER IsGMSAAccount
[Switch] Is the account credential a GMSAAccount
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true, Position=0)]
[Microsoft.Web.Administration.ApplicationPool]$appPool,
[Parameter(Mandatory=$true, Position=1)]
[PSCredential]$Credential,
[Parameter(Mandatory=$false, Position=2)]
[switch]$IsGMSAAccount
)
$logLead = (Get-LogLeadName)
$appPool.ProcessModel.IdentityType = [Microsoft.Web.Administration.ProcessModelIdentityType]::SpecificUser
Write-Verbose "$logLead : Setting ExecutionUser (GMSA: $IsGMSAAccount) to @($Credential.UserName)"
$appPool.ProcessModel.UserName = $Credential.UserName
if (!$IsGMSAAccount) {
Write-Verbose "$logLead : Setting Password on $($appPool.Name)"
$appPool.ProcessModel.Password = (Get-PasswordFromCredential $Credential)
}
}