How to set IIS ApplicationPool "Private Memory Limit" value using PowerShell

Alexander Doroshenko picture Alexander Doroshenko · Jun 25, 2012 · Viewed 9.9k times · Source

I'm using PowerShell for auto-deploying website, and recently found AppPool setting which cannot be set with PS. or at least I did not manage to find out how to do it.

$appPool = $serverManager.ApplicationPools.Add($sitename)...

I need to set "Private Memory Limit" to some value, but it looks like there is no such property at ApplicationPool or ApplicationPoolRecycling object.

Does anybode know workaround for this issue?

Answer

David Martin picture David Martin · Jun 25, 2012

This script uses Get-Webconfiguration and Set-WebConfiguration to get the value for private memory for all app pools. You can set each individually or set the application pool defaults for them to inherit. I have commented out the line which actually does the set.

import-module webadministration

$applicationPoolsPath = "/system.applicationHost/applicationPools"
$applicationPools = Get-WebConfiguration $applicationPoolsPath

foreach ($appPool in $applicationPools.Collection)
{
    $appPoolPath = "$applicationPoolsPath/add[@name='$($appPool.Name)']"
    Get-WebConfiguration "$appPoolPath/recycling/periodicRestart/@privateMemory" 
    # Set-WebConfiguration "$appPoolPath/recycling/periodicRestart/@privateMemory" -Value 1000
}