简体   繁体   中英

How to remotely change IIS Application Pool setting via PowerShell?

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!

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

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
     } 
}

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM