Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 437
Alexander Doroshenko Avatar asked Oct 23 '25 15:10

Alexander Doroshenko


2 Answers

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
}
like image 79
David Martin Avatar answered Oct 25 '25 12:10

David Martin


I am adding an answer because I was having trouble using the existing.

import-module webadministration
$applicationPools = Get-ChildItem IIS:\AppPools

foreach ($appPool in $applicationPools){
Set-ItemProperty IIS:\AppPools\$appPool.name `
-Name recycling.periodicrestart.privateMemory -Value 7000000
}
like image 38
Morgan Avatar answered Oct 25 '25 14:10

Morgan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!