close
no thumb

PowershellOften times changing Application Pool settings in IIS means having to touch all the Application Pools that are used by a single website. For web farms hosting several websites this can easily get complicated. One way to handle this is to find all the Application Pools within a Website and then update them as needed.

Script Highlights
  • Accept the Website Name as a script parameter
  • Validate that the Website Name is valid
  • Use the Get-WebApplication cmdlet to load all the Applications in the Website
  • Store the Application Pool names in an array
  • Enumerate through the Application Pools in the array and update properties on each one
Script IIS Application Pool Changes
param ([Parameter(Mandatory=$true)] [String]$Site )

Write-Host ""
Write-Host "                                                            " -BackgroundColor DarkCyan
Write-Host "              IIS Script                                    " -BackgroundColor DarkCyan
Write-Host "       Update Application Pools                             " -BackgroundColor DarkCyan
Write-Host "                                                            " -BackgroundColor DarkCyan
Write-Host ""

Import-Module WebAdministration -ErrorAction SilentlyContinue

# Check if the Website Exists
if (dir IIS:\Sites\$Site -ErrorAction SilentlyContinue) {Write-Host "Checking $Site Configuration"}else{
	Write-host "$Site does not exist, exiting" -ForegroundColor Red -BackgroundColor Black
	Write-Host ""
	exit
}
Write-Host ""

# Application Pools
$pools = @()

# Enumerate All the Applications in that Website
foreach ($a in Get-WebApplication -site $Site){
	# Add to Array
	if (!($pools -contains ($a.applicationPool))){
		$pools += ($a.applicationPool)
	}
}

# Update Each App Pool
Write-Host "Updating Application Pool Settings"
foreach ($p in $pools){
	Write-Host "Updating $p...."
	Set-ItemProperty iis:\apppools\$p  -name processModel -value @{idletimeout="0"}
	Set-ItemProperty iis:\apppools\$p -Name enable32BitAppOnWin64 -Value $true
	Write-Host "Set $p to idletimeout=0 and 32-Bit=True"
	Write-Host ""
}

Write-Host "Done"
Write-Host ""
Write-Host "                                                            " -BackgroundColor DarkCyan


Tags : iispowershell
Byron Pate

The author Byron Pate