ps/Modules/Alkami.DevOps.Installation/Public/Set-RapidFailSettings.ps1

48 lines
1.9 KiB
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function Set-RapidFailSettings {
<#
.SYNOPSIS
Sets the Rapid-Fail Protection settings for all AppPools configured
on the current server for use with AppPool-Shutdown-Alert.exe
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory = $false)]
[Alias("exePath")]
[string]$autoShutdownExePath = "C:\Tools\AppPool-Shutdown-Alert\AppPool-Shutdown-Alert.exe"
)
try{
Add-Type -Path (Get-ChildItem -Path "C:\Windows\assembly\" -Include "Microsoft.Web.Administration.dll" -Recurse).FullName
$iis = New-Object Microsoft.Web.Administration.ServerManager
if(!(Test-Path $autoShutdownExePath))
{
Write-Warning("Path $autoShutdownExePath does not already exist.")
Write-Warning("Verify that AppPool-Shutdown-Alert has been installed with chocolatey or this alert will not work. It will create the path above.")
Write-Warning("Run 'choco install AppPool-Shutdown-Alert -y' on the target server to install it.")
Write-Warning("Application Pool settings will still be changed.`n`n")
}
foreach ($applicationPool in $iis.ApplicationPools)
{
Write-Host("Current Application Pool: $($applicationPool.Name)")
Write-Host("AutoShutdownExe is set to: $($applicationPool.Failure.AutoShutdownExe)")
Write-Host("Setting AutoShutdownExe to: $autoShutdownExePath")
Write-Host("Setting AutoShutdownParams to: $($applicationPool.Name)`n")
$applicationPool.Failure.AutoShutdownExe = $autoShutdownExePath
$applicationPool.Failure.AutoShutdownParams = $applicationPool.Name
}
}
catch
{
Write-Error("An error occurred while trying to set Application Pool settings:")
Write-Error $_
}
$iis.CommitChanges()
Write-Host("Application Pool changes committed successfully.`n")
}