簡體   English   中英

我可以使用PowerShell而不是AppCmd.exe來監控IIS狀態嗎?

[英]Can I use PowerShell instead of AppCmd.exe to monitor IIS state?

我想編寫一個使用appcmd.exe監視IIS狀態的腳本 - 如果站點關閉則重新啟動站點,和/或如果IIS關閉則重新啟動IIS。

這可以用powershell完成嗎? 這樣做有更自然/更簡單的方法嗎?

謝謝 :-)

Windows PowerShell始終是答案! 這應該針對您的特定問題:

# Cycle IIS if it's not running    
Get-Service W3SVC  |
    Where-Object {$_.Status -ne 'Running' }  | 
    Start-Service

Import-Module WebAdministration

# Cycle websites that are not started
Get-Website | 
    Where-Object { $_.State -ne 'Started' }  | 
    ForEach-Object { $_.Start() } 

希望這可以幫助

您可以使用WebAdministration模塊以比使用appcmd更優雅的方式執行此操作。

http://technet.microsoft.com/en-us/library/ee790599.aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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