How to check app pool last recycled

前端 未结 6 1092
轮回少年
轮回少年 2020-12-29 01:57

is it possible to check when i recycled the app pool last time, i want to check the date when my app pool was last recycled, is there anything in IIS i can get this info.

6条回答
  •  梦毁少年i
    2020-12-29 02:08

    Get the worker process uptime(Recommended):

    $poolName = 
    $poolProcess =(gwmi -NS 'root\WebAdministration' -class 'WorkerProcess' | select AppPoolName,ProcessId | Where-Object { $_.AppPoolName -eq $poolName } )
    
    $lastStartTime=(Get-Process -Id $poolProcess.ProcessId).StartTime
    write-output $lastStartTime
    

    For it to work, make sure you have 'IIS management scripts and tools' enabled.

    Second, way is using Event log, if enabled

    Get-Eventlog -LogName system -Newest 1 -Source "WAS" -Message "*recycle of all worker processes in application pool '$poolName'*")
    

    With Get-Eventlog you can use -After/-Before argument to further limit the result.

    To check if Application pool is recycled in last 'X' minutes, following powershell snippet can be used:

    function isRecycledInLastNMinutes($appPoolName, $lminutes){
        $beforeDate = Get-Date -format 'u'
        $afterDate = $beforeDate.addMinutes(-$lminutes)
        $result = (Get-Eventlog -LogName system -Newest 1 -Source "WAS" -After $afterDate -Before $beforeDate -Message "*recycle of all worker processes in application pool '$appPoolName'*")
        if( $result.length -eq 1){
            return $true
        }else{
            retrun $false
        }
    }
    

提交回复
热议问题