简体   繁体   English

如何通过PowerShell远程更改IIS应用程序池设置?

[英]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.

相关问题 如何在IIS 8中远程停止/启动应用程序池 - How to remotely stop/start an application pool in IIS 8 如何一次远程更改多台服务器上的 IIS 应用程序池密码? - How to change IIS app pool password on multiple servers at once remotely? 使用Powershell在IIS中设置网站的应用程序池 - Setting a website's application pool in IIS using Powershell 如何使用 PowerShell 远程检查 Web 应用程序池的状态? - How to remotely check the status of a web application pool with PowerShell? 如何通过PowerShell设置IIS网站(不是应用程序池)标识字段(用户名和密码)? - How can I set up IIS website (not Application Pool) identity fields (username & password) via PowerShell? 在 C#/Powershell 中 - 是否可以更改 IIS 应用程序池的空闲超时? - in C#/Powershell - Is it possible to change the Idle TimeOut for an IIS Application Pool? 如何从 Powershell 更改 IIS 应用程序池属性 setProfileEnvironment? - How can I change IIS application pool property setProfileEnvironment from Powershell? 如何使用Powershell远程更改IIS日志位置 - how to change iis log location remotely using powershell 如何使用powershell脚本启动和停止IIS中的应用程序池 - How to start and stop application pool in IIS using powershell script 通过powershell远程按需设置壁纸 - Remotely setting wallpaper on demand via powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM