我正在使用IIS 6.0并寻找停止/启动应用程序池的方法。我知道7.0中有一个适用于PowerShell的stop-appPool,但使用6.0。 :-(因此,没有人有一个PowerShell脚本或其他命令行exe文件,将停止/启动应用程序池?使用Powershell或命令行启动/停止应用程序池IIS6.0
感谢。
我正在使用IIS 6.0并寻找停止/启动应用程序池的方法。我知道7.0中有一个适用于PowerShell的stop-appPool,但使用6.0。 :-(因此,没有人有一个PowerShell脚本或其他命令行exe文件,将停止/启动应用程序池?使用Powershell或命令行启动/停止应用程序池IIS6.0
感谢。
确定这里是这样,我只需添加一个开关停止应用程序池其他它,因为没有坏处开始在这起已启动一个应用程序池:
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()
}
}
你可能有兴趣在这个PowerShell的图书馆,我开始维护:
psDeploy:http://rprieto.github.com/psDeploy/
在其他方面也有很多的cmdlet的IIS6的自动化,例如启动IIS6AppPool,新IIS6Website ...
我希望它能帮助!
你可以创建一个函数来停止或启动如下远程应用程序池:
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")
}
}
如果有人正在寻找一个纯粹的命令行工具,不需要PowerShell中,我有created such a thing基础上,包含在其他答案中的信息。由于原来的问题是专门寻找可能的命令行替代方案,我以为我会在这里分享它。
用法很简单:
IIS6AppPool Start DefaultAppPool
IIS6AppPool Stop AppPool #1
IIS6AppPool Recycle Some other app pool
如果在Windows Server 2003上它更容易使用所提供的脚本iisapp.vbs
CScript.exe C:\WINDOWS\system32\iisapp.vbs /?
CScript.exe C:\WINDOWS\system32\iisapp.vbs /a MyApp /r
或者根据您的设置(默认为Cscript不WScript的),只是
iisapp /a MyApp /r
当然它是不同的IIS7
如果你希望这样做远程,和/或在没有PowerShell的机器上,你可以修改脚本发布编号here。
它使用WMI从VBScript访问和回收应用程序池。使它停止/启动池而不是回收它们是一个微不足道的变化,您只需在有问题的应用程序池中调用.Stop
或.Start
即可。
脚本的肉被意译如下:
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
如果你有某种命令行/批处理工具链要这个融入,可以通过执行命令行模式VBScript文件美其名曰:
CScript.exe \NoLogo MyScriptFile.vbs
的\ NOLOGO开关删除VBScript解释的启动消息和CScript.exe中手段运行它,调用WScript.Echo
进入命令行,而不是一个弹出窗口。
看起来您可以通过WMI执行此操作,因此您只需将其转换为PowerShell:http://blogs.iis.net/chrisad/archive/2006/08/30/Recycling-Application-Pools-using- WMI-在-IIS-6.0.aspx。 – 2010-02-12 01:40:17