117 lines
5.8 KiB
PowerShell
117 lines
5.8 KiB
PowerShell
|
Function Set-AlkamiWebAppPoolConfiguration {
|
|||
|
<#
|
|||
|
.SYNOPSIS
|
|||
|
Create a new web app pool with the Alkami configurations as expected
|
|||
|
|
|||
|
.DESCRIPTION
|
|||
|
Create a new web app pool with the Alkami configurations as expected
|
|||
|
|
|||
|
.OUTPUTS
|
|||
|
Returns the application pool that was created
|
|||
|
|
|||
|
.PARAMETER AppPoolName
|
|||
|
[string] The name of the web application pool
|
|||
|
|
|||
|
.EXAMPLE
|
|||
|
Set-AlkamiWebAppPoolConfiguration "cole23423444444"
|
|||
|
|
|||
|
Note the return at the end of the method for the object itself
|
|||
|
|
|||
|
PS Z:\> Set-AlkamiWebAppPoolConfiguration "cole23423444444"
|
|||
|
nothing to configure for cole23423444444 - /autoStart:true
|
|||
|
nothing to configure for cole23423444444 - /enable32BitAppOnWin64:false
|
|||
|
[Set-AlkamiWebAppPoolConfiguration] : Setting AppPool cole23423444444 Config to /managedRuntimeVersion:'v4.0'
|
|||
|
[Set-AlkamiWebAppPoolConfiguration] : Setting AppPool cole23423444444 Config to /queueLength:"5000"
|
|||
|
[Set-AlkamiWebAppPoolConfiguration] : Setting AppPool cole23423444444 Config to /startMode:"AlwaysRunning"
|
|||
|
[Set-AlkamiWebAppPoolConfiguration] : Setting AppPool cole23423444444 Config to /processModel.idleTimeout:"00:00:00"
|
|||
|
nothing to configure for cole23423444444 - /processModel.loadUserProfile:true
|
|||
|
[Set-AlkamiWebAppPoolConfiguration] : Setting AppPool cole23423444444 Config to /failure.rapidFailProtectionInterval:"00:10:00"
|
|||
|
[Set-AlkamiWebAppPoolConfiguration] : Setting AppPool cole23423444444 Config to /failure.rapidFailProtectionMaxCrashes:50
|
|||
|
[Set-AlkamiWebAppPoolConfiguration] : Setting AppPool cole23423444444 Config to /recycling.periodicRestart.time:"00:00:00"
|
|||
|
nothing to configure for cole23423444444 - /recycling.LogEventOnRecycle:"Time, Requests, Schedule, Memory, IsapiUnhealthy, OnDemand, ConfigChange, PrivateMemory"
|
|||
|
|
|||
|
Name State .NET Pipeline Identity
|
|||
|
---- ----- ---- -------- --------
|
|||
|
cole23423444444 Started 'v4.0' Integrated ApplicationPoolIdentity
|
|||
|
|
|||
|
#>
|
|||
|
[CmdletBinding()]
|
|||
|
Param(
|
|||
|
[Parameter(Mandatory=$true, Position=0)]
|
|||
|
[Alias("Name")]
|
|||
|
[string]$AppPoolName
|
|||
|
)
|
|||
|
|
|||
|
$logLead = (Get-LogLeadName)
|
|||
|
|
|||
|
$appPool = IISAdministration\Get-IISAppPool -Name $AppPoolName
|
|||
|
|
|||
|
if ($null -eq $appPool) {
|
|||
|
$appPool = WebAdministration\New-WebAppPool -Name $AppPoolName -Force
|
|||
|
}
|
|||
|
|
|||
|
$propertiesToCheck = @(
|
|||
|
"/autoStart:true"
|
|||
|
"/enable32BitAppOnWin64:false"
|
|||
|
"/managedRuntimeVersion:v4.0"
|
|||
|
"/queueLength:`"5000`""
|
|||
|
"/startMode:`"AlwaysRunning`""
|
|||
|
"/processModel.idleTimeout:`"00:00:00`""
|
|||
|
"/processModel.loadUserProfile:true"
|
|||
|
"/failure.rapidFailProtectionInterval:`"00:10:00`""
|
|||
|
"/failure.rapidFailProtectionMaxCrashes:50"
|
|||
|
"/recycling.periodicRestart.time:`"00:00:00`""
|
|||
|
"/recycling.LogEventOnRecycle:`"Time, Requests, Schedule, Memory, IsapiUnhealthy, OnDemand, ConfigChange, PrivateMemory`""
|
|||
|
)
|
|||
|
|
|||
|
$changedProperties = 0
|
|||
|
|
|||
|
## by using the for-loop we can easily add a single new property to check/set
|
|||
|
foreach ($property in $propertiesToCheck) {
|
|||
|
|
|||
|
## This command lists all the apppools that have this property set (since it varies by property, we can't cache it)
|
|||
|
## So we filter the results and look for the matching app pool name to be present in the output
|
|||
|
|
|||
|
## TODO: cbrand ~ This is a terrible line to read. Fix this crap
|
|||
|
## What this command does is
|
|||
|
## 1) negate the results
|
|||
|
## 2) ask appCmdPath to list the application pools with the specified property
|
|||
|
## which gives all of the app pools that match
|
|||
|
## 3) filter to the app pool we care about
|
|||
|
## So we negate the list because if we came back with no records after the filter,
|
|||
|
## then the record we want doesn't exist, so we should set it.
|
|||
|
if (!(Test-AppCommandPropertyExistsOnAppPool -Property $property -AppPoolName $AppPoolName)) {
|
|||
|
Write-Verbose "$logLead : Setting AppPool $AppPoolName Config to $property"
|
|||
|
|
|||
|
Set-AppCommandPropertyOnAppPool -Property $property -AppPoolName $AppPoolName
|
|||
|
|
|||
|
$changedProperties += 1
|
|||
|
} else {
|
|||
|
Write-Verbose "Nothing to configure for $AppPoolName - $property"
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Write-Host "$logLead : Checking to attempt to add User from the configuration settings on this host"
|
|||
|
if (![string]::IsNullOrWhiteSpace((Get-AppSetting "Environment.UserPrefix" -SuppressWarnings))) {
|
|||
|
$appServiceName = (Get-AppServiceAccountName $AppPoolName)
|
|||
|
Write-Host "$logLead : Attempting to add User from the configuration settings on [$AppPoolName] with [$appServiceName]"
|
|||
|
if ((![string]::IsNullOrEmpty($appServiceName)) -and ($appPool.ProcessModel.UserName -ne $appServiceName)) {
|
|||
|
Write-Verbose "$logLead : Setting ExecutionUser for [$AppPoolName] to [$appServiceName]"
|
|||
|
Set-ItemProperty $appPoolPath -name processModel -value @{userName=$appServiceName;identitytype=3}
|
|||
|
## Presume that all accounts are currently on Windows and are gMSA, so no password is needed
|
|||
|
} else {
|
|||
|
if ([string]::IsNullOrEmpty($appServiceName)) {
|
|||
|
Write-Host "$logLead : Could not add a specific user to the app pool as the lookup service name does not exist. This is normal and expected behavior, just informational."
|
|||
|
} else {
|
|||
|
Write-Host "$logLead : No need to change the user as the username is already set correctly."
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return (IISAdministration\Get-IISAppPool -Name $AppPoolName)
|
|||
|
}
|
|||
|
|
|||
|
## TODO: Review all usages of these aliases in the future so we aren't double-doing the work here, since it does it all every time.
|
|||
|
## Alternately: separate things into separate functions and ensure these are always called whenever Set-AlkamiWebAppPoolConfiguration is called.
|
|||
|
Set-Alias -name Get-AlkamiWebAppPool -value Set-AlkamiWebAppPoolConfiguration
|
|||
|
Set-Alias -name New-AlkamiWebAppPool -value Set-AlkamiWebAppPoolConfiguration
|