[英]Start/Stop App Pool IIS6.0 with Powershell or command line
I'm using IIS 6.0 and looking for a way to stop/start the app pool. 我正在使用IIS 6.0并寻找一种方法来停止/启动应用程序池。 I know there is a stop-appPool for powershell in 7.0 but using 6.0. 我知道在7.0版本中有一个用于powershell的stop-appPool但是使用6.0。 :-( So does anyone have a powershell script or another command line exe that will stop/start the app pool? :-(那么有没有人有一个powershell脚本或另一个命令行exe将停止/启动应用程序池?
Thanks. 谢谢。
Ok here it is, I just add a switch to stop the app pool else it starts since no harm in starting an app pool that is already started: 好的,我只是添加了一个开关来停止应用程序池,否则它启动,因为启动已启动的应用程序池没有任何损害:
param([string]$appPoolName, [switch]$stop)
$appPool = get-wmiobject -namespace "root\MicrosoftIISv2" -class "IIsApplicationPool" | where-object {$_.Name -eq "W3SVC/AppPools/$appPoolName"}
if($appPool)
{
if($stop)
{
$appPool.Stop()
}
else
{
$appPool.Start()
}
}
If anybody is looking for a purely command-line tool that does not require Powershell, I have created such a thing based on the information contained in these other answers. 如果有人正在寻找一个不需要Powershell的纯命令行工具,我已根据这些其他答案中包含的信息创建了这样的东西 。 Since the original question is specifically looking for possible command-line alternatives, I thought I would share it here. 由于最初的问题是专门寻找可能的命令行替代品,我想我会在这里分享。
Usage is quite simple: 用法很简单:
IIS6AppPool Start DefaultAppPool
IIS6AppPool Stop AppPool #1
IIS6AppPool Recycle Some other app pool
Source and binaries are available on bitbucket. bitbucket上提供了源代码和二进制文件 。 May this save somebody else a few minutes of head scratching. 愿这可以节省别人几分钟的头痛。
If on Windows Server 2003 it is simpler to use the supplied script iisapp.vbs 如果在Windows Server 2003上使用提供的脚本iisapp.vbs更简单
CScript.exe C:\WINDOWS\system32\iisapp.vbs /?
CScript.exe C:\WINDOWS\system32\iisapp.vbs /a MyApp /r
Or depending on your setup (default to Cscript not WScript), simply 或者,根据您的设置(默认为Cscript而不是WScript),简单地说
iisapp /a MyApp /r
You might be interested in this Powershell library I started maintaining: 您可能对我开始维护的Powershell库感兴趣:
psDeploy : http://rprieto.github.com/psDeploy/ psDeploy : http: //rprieto.github.com/psDeploy/
Among other things it has lots of cmdlets for IIS6 automation, for example Start-IIS6AppPool , New-IIS6Website ... 除此之外,它还有许多用于IIS6自动化的cmdlet,例如Start-IIS6AppPool , New-IIS6Website ......
I hope it helps! 我希望它有所帮助!
If you wish to do this remotely, and / or on a machine without powershell you can modify the script posted here . 如果您希望远程执行此操作,和/或在没有PowerShell的计算机上执行此操作,则可以修改此处发布的脚本。
It uses WMI to access and recycle the app pool, from VBScript. 它使用WMI从VBScript访问和回收应用程序池。 It's a trivial change to make it stop / start pools instead of recycling them, you just need to call .Stop
or .Start
on the app pool in question. 使它停止/启动池而不是回收它是一个微不足道的变化,你只需要在相关的应用程序池上调用.Stop
或.Start
。
The meat of the script is paraphrased below: 脚本的内容在下面解释:
strServer = "LocalHost" 'Server name goes here
strAppPoolName = "MyAppPool" 'App pool name goes here
'Connect to the specified server using WMI
set Locator = CreateObject("WbemScripting.SWbemLocator")
Locator.Security_.AuthenticationLevel = 6
set Service = locator.connectserver(strServer,"root/MicrosoftIISv2")
'Get a collection of WMI apppools
set APCollection = Service.InstancesOf("IISApplicationPool")
For each APInstance in APCollection
If UCase(ApInstance.Name) = UCase("W3SVC/AppPools/" & strAppPoolName) Then
WScript.Echo "Recycling " & strServer & "/" & APInstance.Name
' You can do any of these things depending you what you want to do.
APInstance.Recycle
APInstance.Stop
APInstance.Start
End If
Next
If you have some kind of command line / batch toolchain which you want to integrate this into, you can execute a VBScript file in command line mode by calling: 如果您要将某些命令行/批处理工具链集成到其中,则可以通过调用以下命令行模式执行VBScript文件:
CScript.exe \NoLogo MyScriptFile.vbs
The \\NoLogo switch removes the VBScript interpreter startup messages and running it with CScript.exe means that calls to WScript.Echo
go to the command line rather than a popup window. \\ NoLogo开关删除VBScript解释器启动消息,并使用CScript.exe运行它意味着对WScript.Echo
调用转到命令行而不是弹出窗口。
You could create a function to stop or start the application pool remotely as below: 您可以创建一个远程停止或启动应用程序池的功能,如下所示:
function StopOrStartAppPool($RemoteServerName, $AppPoolName, $commandWebPool)
{
if ($commandWebPool -eq "Stop")
{
$wmiprocess = [wmiclass]"\\$RemoteServerName\root\cimv2:win32_process"
$wmiprocess.create("cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs STOP_SERVER W3SVC/AppPools/$AppPoolName -s:$RemoteServerName")
}
else
{
$wmiprocess = [wmiclass] "\\$RemoteServerName\root\cimv2:win32_process"
$wmiprocess.create("cscript.exe C:\Inetpub\AdminScripts\adsutil.vbs START_SERVER W3SVC/AppPools/$AppPoolName -s:$RemoteServerName")
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.