1.右键tool,run as admin;需要联系我:Tianyou.Lan
2.自动检测完成。
经历了一段时间的研究与学习,我终于完成了这个为检查打Hotfix之后agent端Application/IIS是否重启过的自动化解决方案,并且通过了几轮针对性的测试。如果大家在使用过程中遇到了问题请联系我lync:tianyou lan
#获取w3wp进程所对应的Application pool(这个函数是在网上搜的)
function global:get-apppools{
[regex]$pattern="-ap ""(.+)"""
gwmi win32_process -filter 'name="w3wp.exe"' | % {
$name=$_.name
$cmd = $pattern.Match($_.commandline).Groups[1].Value
$procid = $_.ProcessId
New-Object psobject | Add-Member -MemberType noteproperty -PassThru Name $name |
Add-Member -MemberType noteproperty -PassThru AppPoolID $cmd |
Add-Member -MemberType noteproperty -PassThru PID $procid
}
}
#最新W3Wp进程开启的时间
SilentlyContinue
if($global:W3WPSProcesses -is [array]){
#如果有很多的w3wp进程,取最新的那个。
$global:W3WPStartTime=0
for($j=0;$j -lt $global:W3WPSProcesses.length;$j++){
if($global:W3WPSProcesses[$j].StartTime -gt $global:W3WPStartTime){
$global:W3WPStartTime=$global:W3WPSProcesses[$j].StartTime
}
}
}else{
#只有一个w3wp进程时,获取到w3wp进程的starttime。
$global:W3WPStartTime=$global:W3WPSProcesses.StartTime
}
#最近一个Hotfix开始的时间
$global:HotfixLog=Get-EventLog avepoint|Where-Object {$_.Category -like "*Update Manager*"}
if($global:HotfixLog -is [array]){
#0位为最新的Hotfix时间
$global:HotfixTime=$global:HotfixLog[0].TimeWritten
}else{
$global:HotfixTime=$global:HotfixLog.TimeWritten
}
function CheckPool{
begin{
$global:NewOrOldProcess=0
$global:Old=0
$global:New=0
}
process{
if($_.starttime -gt $global:HotfixTime){
$global:NewOrOldProcess=$global:NewOrOldProcess+1
$global:Old=$global:Old+1
$global:New=$global:New+1
$global:process=$_
$global:nameofthepool=(global:get-apppools|Where-Object {$_.pid -eq $global:process.id}).apppoolid
$global:IndexOfEnd=$global:nameofthepool.indexof('"')
$global:shortNameOfThePool=$global:nameofthepool.substring(0,$global:IndexOfEnd)
Write-Host "The application pool [ $global:shortNameOfThePool ] has reset or the w3wp process of it is new created after the 'Hotfix' updated."
Write-Host "-----------------------"
}else{
$global:Old=$global:Old+1
$global:process=$_
$global:nameofthepool=(global:get-apppools|Where-Object {$_.pid -eq $global:process.id}).apppoolid
$global:IndexOfEnd=$global:nameofthepool.indexof('"')
$global:shortNameOfThePool=$global:nameofthepool.substring(0,$global:IndexOfEnd)
Write-Host "The application pool [ $global:shortNameOfThePool ] has not reset after the 'Hotfix' updated."
Write-Host "-----------------------"
}
}
end{
if($global:NewOrOldProcess -ne 0){
if($global:New -lt $global:Old){
Write-Host "Through the analysis from 'HotCheck':"
Write-Host "Not all the application pool(s) has been reset or new created after the 'Hotfix' updated."
网易云新用户大礼包:https://www.163yun.com/gift
本文来自博客园天外云归专栏,经作者蓝天祐授权发布。