Skip to main content

IT - Programming - PowerShell 7 - ListSystemBoots.ps1

Expected output

PowerShell 7.5.1
PS C:\Users\afberendsen> .\ListSystemBoots.ps1

Time                EventType        EventID Description
----                ---------        ------- -----------
01/05/2025 23:29:32 Unexpected Reset      41 The system has rebooted without cleanly shutting down first. This error could be caused if the system stopped responding, crashed, or lost power unexpectedly.
01/05/2025 23:28:57 System Boot           20 The last shutdown's success status was false. The last boot's success status was true.
01/05/2025 21:10:14 Unexpected Reset      41 The system has rebooted without cleanly shutting down first. This error could be caused if the system stopped responding, crashed, or lost power unexpectedly.
01/05/2025 21:09:12 System Boot           20 The last shutdown's success status was false. The last boot's success status was true.
01/05/2025 13:38:03 Unexpected Reset      41 The system has rebooted without cleanly shutting down first. This error could be caused if the system stopped responding, crashed, or lost power unexpectedly.
01/05/2025 13:37:20 System Boot           20 The last shutdown's success status was false. The last boot's success status was true.
01/05/2025 10:24:45 Unexpected Reset      41 The system has rebooted without cleanly shutting down first. This error could be caused if the system stopped responding, crashed, or lost power unexpectedly.
01/05/2025 10:24:00 System Boot           20 The last shutdown's success status was false. The last boot's success status was true.
30/04/2025 07:29:07 Unexpected Reset      41 The system has rebooted without cleanly shutting down first. This error could be caused if the system stopped responding, crashed, or lost power unexpectedly.
30/04/2025 07:28:17 System Boot           20 The last shutdown's success status was false. The last boot's success status was true.
27/04/2025 23:22:40 System Boot           20 The last shutdown's success status was true. The last boot's success status was true.
26/04/2025 00:34:28 System Boot           20 The last shutdown's success status was true. The last boot's success status was true.
19/04/2025 00:16:16 System Boot           20 The last shutdown's success status was true. The last boot's success status was true.
16/04/2025 17:59:38 System Boot           20 The last shutdown's success status was true. The last boot's success status was true.
14/04/2025 23:30:39 Unexpected Reset      41 The system has rebooted without cleanly shutting down first. This error could be caused if the system stopped responding, crashed, or lost power unexpectedly.
14/04/2025 23:29:55 System Boot           20 The last shutdown's success status was false. The last boot's success status was true.
14/04/2025 21:37:35 System Boot           20 The last shutdown's success status was true. The last boot's success status was true.
14/04/2025 21:16:05 System Boot           20 The last shutdown's success status was true. The last boot's success status was true.

PS C:\Users\afberendsen>

Source Code

# Get system boot events, including unexpected resets
$bootEvents = Get-WinEvent -FilterHashtable @{
    LogName = 'System'
    ProviderName = 'Microsoft-Windows-Kernel-Boot'
    Id = 20  # Event ID 20 indicates system boot
} -ErrorAction SilentlyContinue

$unexpectedEvents = Get-WinEvent -FilterHashtable @{
    LogName = 'System'
    ProviderName = 'Microsoft-Windows-Kernel-Power'
    Id = 41  # Event ID 41 indicates unexpected shutdown/reset
} -ErrorAction SilentlyContinue

# Combine and sort events by time
$allEvents = @($bootEvents + $unexpectedEvents) | Sort-Object TimeCreated -Descending

# Display relevant details
$allEvents | ForEach-Object {
    $eventType = if ($_.Id -eq 20) { "System Boot" } else { "Unexpected Reset" }
    [PSCustomObject]@{
        Time        = $_.TimeCreated
        EventType   = $eventType
        EventID     = $_.Id
        Description = $_.Message
    }
} | Format-Table -AutoSize

Comments

Popular posts from this blog

Movies - The Bubble (2022)

  Back to Evolution (2001) .

IT - Fixing Windows Error 1327: Account Restrictions Are Preventing This User from Signing In

Fixing Windows Error 1327: Account Restrictions Are Preventing This User from Signing In Introduction Error 1327, “Account restrictions are preventing this user from signing in,” is a perplexing and disruptive issue that occurs on some Windows 10 and Windows 11 machines. The message typically appears at login or while connecting to remote resources, like shared folders, network drives, or remote desktops. Table of Contents Symptoms of Error 1327 Common Causes Step-by-Step Troubleshooting Advanced Fixes Automation via PowerShell Prevention Tips Further Reading Symptoms of Error 1327 Users experiencing this error may encounter one or more of the following: Login screen fails after credentials are entered. Error message appears when accessing mapped drives or network resources. Remote Desktop Connection (RDP) is rejected with the 1327 message. Group Policy logon restrictions silently block access. Co...

ATA Drive Capacity Limitations

ATA interface versions up through ATA-5 suffered from a drive capacity limitation of about 137GB (billion bytes). Depending on the BIOS used, you can further reduce this limitation to 8.4GB, or even as low as 528MB (million bytes). This is due to limitations in both the BIOS and the ATA interface, which when combined create even further limitations. To understand these limits, you have to look at the BIOS (software) and ATA (hardware) interfaces together. NOTE In addition to the BIOS/ATA limitations discussed in this section, various operating system limitations exist. These are described later in this chapter. The limitations when dealing with ATA drives are those of the ATA interface as well as the BIOS interface used to talk to the drive. A summary of the limitations is shown in Table 7.12. Table 7.12. ATA/IDE Capacity Limitations for Various Sector Addressing Methods Sector Addressing Method Total Sectors Calculation Maximum Total Sectors Maximum Capacity (Byte...