[英]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更优雅的方式执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.