使用Powershell或命令行启动/停止应用程序池IIS6.0

发布于 2024-08-21 09:32:36 字数 149 浏览 7 评论 0原文

我正在使用 IIS 6.0 并寻找一种停止/启动应用程序池的方法。我知道7.0中有一个用于powershell的stop-appPool,但使用的是6.0。 :-( 那么有人有一个 powershell 脚本或另一个命令行 exe 可以停止/启动应用程序池吗?

谢谢。

I'm using IIS 6.0 and looking for a way to stop/start the app pool. I know there is a stop-appPool for powershell in 7.0 but using 6.0. :-( So does anyone have a powershell script or another command line exe that will stop/start the app pool?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

杯别 2024-08-28 09:32:36

好的,就是这样,我只是添加一个开关来停止应用程序池,否则它会启动,因为启动已经启动的应用程序池没有任何害处:

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

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()
   }
}
此刻的回忆 2024-08-28 09:32:36

如果有人正在寻找不需要 Powershell 的纯命令行工具,我已经创建了这样一个东西 基于这些其他答案中包含的信息。由于最初的问题是专门寻找可能的命令行替代方案,因此我想我会在这里分享它。

用法非常简单:

IIS6AppPool Start DefaultAppPool
IIS6AppPool Stop AppPool #1
IIS6AppPool Recycle Some other app pool

来源二进制文件 可在 bitbucket 上获取。也许这可以让其他人免去几分钟的苦恼。

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. 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. May this save somebody else a few minutes of head scratching.

羁客 2024-08-28 09:32:36

您可能对我开始维护的这个 Powershell 库感兴趣:

psDeployhttp:// rprieto.github.com/psDeploy/

除此之外,它还有许多用于 IIS6 自动化的 cmdlet,例如 Start-IIS6AppPoolNew-IIS6Website...

我希望它有帮助!

You might be interested in this Powershell library I started maintaining:

psDeploy : http://rprieto.github.com/psDeploy/

Among other things it has lots of cmdlets for IIS6 automation, for example Start-IIS6AppPool, New-IIS6Website...

I hope it helps!

苹果你个爱泡泡 2024-08-28 09:32:36

如果在 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

If on Windows Server 2003 it is simpler to use the supplied script 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

iisapp /a MyApp /r

And of course it is different in IIS7

榕城若虚 2024-08-28 09:32:36

如果您希望远程执行此操作,和/或在没有 powershell 的计算机上执行此操作,您可以修改 此处发布的脚本

它使用 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 的调用将转到命令行而不是弹出窗口。

If you wish to do this remotely, and / or on a machine without powershell you can modify the script posted here.

It uses WMI to access and recycle the app pool, from 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.

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:

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.

伏妖词 2024-08-28 09:32:36

您可以创建一个函数来远程停止或启动应用程序池,如下所示:

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

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")      
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文