我想編寫一個腳本,使用appcmd.exe來監視IIS狀態 - 如果站點已關閉,則重新啓動站點和/或在IIS關閉時重新啓動它。我可以使用PowerShell而不是AppCmd.exe來監視IIS狀態嗎?
這可以用PowerShell來完成嗎?有沒有更自然/更簡單的方法來做到這一點?
感謝:-)
我想編寫一個腳本,使用appcmd.exe來監視IIS狀態 - 如果站點已關閉,則重新啓動站點和/或在IIS關閉時重新啓動它。我可以使用PowerShell而不是AppCmd.exe來監視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更優雅的方式。
優秀!謝謝。 – strum 2011-12-22 09:53:12