1

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!

1
  • You want to change for all appPools (machine level) or for a specific appPool? Commented Jan 18, 2016 at 22:14

3 Answers 3

1

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
     } 
}
Sign up to request clarification or add additional context in comments.

Comments

1

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
}

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.