【问题标题】:Can I use PowerShell instead of AppCmd.exe to monitor IIS state?我可以使用 PowerShell 而不是 AppCmd.exe 来监视 IIS 状态吗?
【发布时间】:2011-12-21 21:12:49
【问题描述】:

我想编写一个使用 appcmd.exe 来监控 IIS 状态的脚本 - 如果站点关闭则重新启动站点和/或如果站点关闭则重新启动 IIS。

这可以用powershell完成吗?有没有更自然/更简单的方法来做到这一点?

谢谢:-)

【问题讨论】:

    标签: iis powershell appcmd


    【解决方案1】:

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

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      您可以使用WebAdministration 模块以比使用 appcmd 更优雅的方式执行此操作。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-01-22
        • 1970-01-01
        • 2022-01-15
        • 2022-09-22
        • 2014-07-12
        • 1970-01-01
        • 2020-04-29
        相关资源
        最近更新 更多