40 lines
1.1 KiB
PowerShell
40 lines
1.1 KiB
PowerShell
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)
|
|
}
|
|
}
|
|
|