1
votes

I am trying to use PowerShell to iterate through a list of servers and change the 'MaxProcesses' value under 'ProcessModel' (found in Advanced Settings of Application Pool in IIS)

I have already figured out how to remotely start and stop application pools but I cannot seem to nail down how to modify settings.

Your help is appreciated!

PS - I am using Get-WmiObject to build the $appPool object where I call $appPool.Stop() and $appPool.Start(). Any ways to update settings also using this object, I'd be grateful!

3
You want to change for all appPools (machine level) or for a specific appPool?dugas

3 Answers

1
votes

This should do the trick for setting the maxProcesses (webgarden) setting.

$appPoolName = "SomeAppPool"
$maxProcesses = 4

Import-Module WebAdministration

$appPool = Get-ChildItem IIS:\AppPools\ | Where-Object { $_.Name -eq $appPoolName }
if($appPool)
{
   $appPool | Set-ItemProperty -Name "processModel.maxProcesses" -Value $maxProcesses
}
0
votes

This doesn't address the 'remotely change' part; only the command to set the desired attribute:

import-module webadministration

# tell script where to look for appcmd.exe, else it gives a 'cmd not found' error
Set-Location %systemroot%\system32\inetsrv

.\appcmd.exe set apppool "NameOfYourAppPoolGoesHere" /processModel.maxprocesses:3

reference: https://www.iis.net/configreference/system.applicationhost/applicationpools/add/processmodel

0
votes

You can use this snippet:

$computerName = 'MyServerName'
$appPoolName = 'DefaultAppPool'

Stop application pool:

Invoke-Command -ComputerName $computerName -args $appPoolName -ScriptBlock { 
    param($appPoolName) 
    # Check if application pool is already stopped
    if ((Get-WebAppPoolState -name $appPoolName).value -ne 'Stopped') {
        Stop-WebAppPool -Name $appPoolName
     } 
}

Stop application pool:

Invoke-Command -ComputerName $computerName -args $appPoolName -ScriptBlock { 
   param($appPoolName) 
    # Check if application pool is already started
    if ((Get-WebAppPoolState -name $appPoolName).value -ne 'Started') {
        Start-WebAppPool -Name $appPoolName
     } 
}