簡體   English   中英

使用Powershell或命令行啟動/停止App Pool IIS6.0

[英]Start/Stop App Pool IIS6.0 with Powershell or command line

我正在使用IIS 6.0並尋找一種方法來停止/啟動應用程序池。 我知道在7.0版本中有一個用於powershell的stop-appPool但是使用6.0。 :-(那么有沒有人有一個powershell腳本或另一個命令行exe將停止/啟動應用程序池?

謝謝。

好的,我只是添加了一個開關來停止應用程序池,否則它啟動,因為啟動已啟動的應用程序池沒有任何損害:

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的純命令行工具,我已根據這些其他答案中包含的信息創建了這樣的東西 由於最初的問題是專門尋找可能的命令行替代品,我想我會在這里分享。

用法很簡單:

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

bitbucket上提供了源代碼二進制文件 願這可以節省別人幾分鍾的頭痛。

如果在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庫感興趣:

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

除此之外,它還有許多用於IIS6自動化的cmdlet,例如Start-IIS6AppPoolNew-IIS6Website ......

我希望它有所幫助!

如果您希望遠程執行此操作,和/或在沒有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調用轉到命令行而不是彈出窗口。

您可以創建一個遠程停止或啟動應用程序池的功能,如下所示:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM