82 lines
3.0 KiB
PowerShell
82 lines
3.0 KiB
PowerShell
#requires -version 4.0
|
|
#requires -runasadministrator
|
|
|
|
#Retrieving all events with ID 100
|
|
|
|
$BootEvents = Get-WinEvent -FilterHashtable @{
|
|
logname='Microsoft-Windows-Diagnostics-Performance/Operational';
|
|
id=100}
|
|
|
|
#Building a boot history with, for each boot, the duration of the boot process
|
|
|
|
$BootHistory = $BootEvents | Select-Object TimeCreated, LevelDisplayName,
|
|
@{
|
|
n="BootStartTime";
|
|
e={Get-Date -Date (([xml]$_.ToXml()).Event.EventData.Data |
|
|
Where-Object {$_.name -eq "BootStartTime"})."#text"}
|
|
},
|
|
@{
|
|
n="BootEndTime";
|
|
e={Get-Date -Date (([xml]$_.ToXml()).Event.EventData.Data |
|
|
Where-Object {$_.name -eq "BootEndTime"})."#text"}
|
|
},
|
|
@{
|
|
n="MainPathBootTime";
|
|
e={([timespan]::FromMilliseconds((([xml]$_.ToXml()).Event.EventData.Data |
|
|
Where-Object {$_.name -eq "MainPathBootTime"})."#text"))}
|
|
},
|
|
@{
|
|
n="BootPostBootTime";
|
|
e={([timespan]::FromMilliseconds((([xml]$_.ToXml()).Event.EventData.Data |
|
|
Where-Object {$_.name -eq "BootPostBootTime"})."#text"))}
|
|
}
|
|
|
|
$BootStartTime = $BootHistory.bootstarttime
|
|
|
|
$MainPathBootTime = $BootHistory.MainPathBootTime
|
|
|
|
$PostBootTime = $BootHistory.BootPostBootTime
|
|
|
|
$LastBootDate = $BootStartTime | Select-Object -First 1
|
|
|
|
$OldestRecordedBoot = $BootStartTime | Select-Object -last 1
|
|
|
|
$BootFrequencyInDays = ($LastBootDate - $OldestRecordedBoot).days / $BootStartTime.Count
|
|
|
|
$AvgMainBootDuration = [timespan]::FromSeconds((($MainPathBootTime.totalseconds |
|
|
Measure -A).average)).ToString("hh\:mm\:ss")
|
|
|
|
$AvgPostBootDuration = [timespan]::FromSeconds((($PostBootTime.totalseconds |
|
|
Measure -A).average)).ToString("hh\:mm\:ss")
|
|
|
|
$ActualWindowsBootTime = (Get-Date) - `
|
|
([timespan]::FromMilliseconds([Math]::Abs([Environment]::TickCount)))
|
|
|
|
$LastEvent12 = Get-WinEvent -FilterHashtable @{
|
|
LogName='System';
|
|
ProviderName='Microsoft-Windows-Kernel-General';
|
|
ID=12} -MaxEvents 1 | Select -ExpandProperty TimeCreated
|
|
|
|
|
|
#Building an object containing a quick summary of your last computer boot, as
|
|
#well as of the average boot duration.
|
|
|
|
$BootInformation = 1 | Select-Object BootFrequencyInDays, AvgMainBootDuration, `
|
|
AvgPostBootDuration, LastBootDate, OldestRecordedBoot, `
|
|
ActualWindowsBootTime, LastEvent12
|
|
$BootInformation.BootFrequencyInDays = $BootFrequencyInDays
|
|
$BootInformation.AvgMainBootDuration = $AvgMainBootDuration
|
|
$BootInformation.AvgPostBootDuration = $AvgPostBootDuration
|
|
$BootInformation.LastBootDate = $LastBootDate
|
|
$BootInformation.OldestRecordedBoot = $OldestRecordedBoot
|
|
$BootInformation.ActualWindowsBootTime = $ActualWindowsBootTime
|
|
$BootInformation.LastEvent12 = $LastEvent12
|
|
|
|
#Grouping boot events by Level, in order to see if your computer boot duration is below or
|
|
#beyond the thresholds defined in the Registry
|
|
$BootAnalysis = Get-WinEvent -FilterHashtable @{
|
|
logname='Microsoft-Windows-Diagnostics-Performance/Operational';
|
|
id=100} |
|
|
Group-Object LevelDisplayName
|
|
|
|
$BootHistory | Out-Gridview |