【问题标题】:Powershell to get IIS application initialization statusPowershell 获取 IIS 应用程序初始化状态
【发布时间】:2016-08-25 18:19:02
【问题描述】:

我的网站将doAppInitAfterRestart 设置为true 并且正在运行,但我想知道应用程序何时完成初始化。

有没有办法通过powershellWMI知道网站的应用初始化什么时候完成?

【问题讨论】:

    标签: powershell iis wmi iis-6


    【解决方案1】:

    试试下面提到的 VB 脚本代码。我已经从我的一个工作脚本中抓取了这段代码,如果您发现任何错误,请发表评论。

    iis_con= "localhost"  
    set WMI_IIS = GetObject( "IIS://" & iis_con & "/W3SVC" )
            if WMI_IIS.count = 0 then 
             ' do nothing
            else 
                for each objitem in WMI_IIS
                    if objitem.class = "IIsWebServer" then
                        Select Case objItem.serverstate
                            Case 1:        wscript.echo("Starting")
                            Case 2:        wscript.echo("Running")
                            Case 3:        wscript.echo("Stopping")
                            Case 4:        wscript.echo("Stopped")
                            Case 5:        wscript.echo("Pausing")
                            Case 6:        wscript.echo("Paused")
                            Case 7:        wscript.echo("Continuing")
                            Case Default:  wscript.echo("Unknown")
                        End Select
                    Next
    end if
    

    【讨论】:

    • 感谢@Amit 的帮助。不完全符合我的要求。在站点启动后(不到一秒),此代码立即启动并继续返回“2”运行状态。这是我用来测试的转换为powershell的代码。 while ( $true ) { $site=get-wmiobject -namespace "root\MicrosoftIISv2" -class "IIsWebServer" -ComputerName localhost -Filter "name='w3svc/4'" $site.serverstate start-sleep -Milliseconds 10 }
    • 我不知道您使用的是 IIS6+,所以没有提供 WMI。那你现在有什么问题吗?我没有从你的评论中弄清楚。
    • 是的,我使用的是 IIS6+。我仍然无法确定应用初始化何时完成。
    猜你喜欢
    • 2016-04-26
    • 1970-01-01
    • 2020-12-30
    • 2017-12-09
    • 2016-05-30
    • 2014-08-30
    • 2013-10-08
    • 2019-10-05
    • 2019-05-08
    相关资源
    最近更新 更多