[英]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) 我正在尝试使用PowerShell遍历服务器列表并更改“ ProcessModel”(在IIS中的“应用程序池”的“高级设置”中找到)下的“ MaxProcesses”值
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(). PS-我正在使用Get-WmiObject构建$ appPool对象,在这里我将其称为$ appPool.Stop()和$ 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 参考: 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. 这应该可以完成设置maxProcesses(webgarden)设置的技巧。
$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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.