How to use the command 'Get-WUHistory' (with examples)

How to use the command 'Get-WUHistory' (with examples)

The Get-WUHistory command is a vital component of the PSWindowsUpdate module in PowerShell. Its primary function is to retrieve the history of updates installed via Windows Update on a Windows operating system. The capability to access detailed records of update installation is crucial for system administrators and users seeking to manage and troubleshoot updates effectively. Given the command’s multitude of options for filtering and formatting output, it’s a powerful tool for monitoring system updates and ensuring everything is up-to-date and functioning correctly.

Use case 1: Get list of update history

Code:

Get-WUHistory

Motivation:

Using Get-WUHistory without any additional parameters provides a comprehensive list of all the updates installed via Windows Update on the machine. This is especially useful for users who want to perform audits or check if their system has received all necessary updates, ensuring security patches and feature enhancements are up-to-date.

Explanation:

  • The command executes with no arguments, instructing PowerShell to fetch the entire history of updates. By default, it retrieves all available data related to when each update was installed, its installation result, and the corresponding update ID.

Example Output:

Date       Time       Status   Title
----       ----       ------   -----
10/10/2023 03:15 PM   Succeeded Security Update for Windows (KB1234567)
10/01/2023 07:00 AM   Failed    Cumulative Update for Windows (KB8901234)
09/20/2023 05:30 AM   Succeeded Update for Microsoft Office (KB2345678)

Use case 2: List the last 10 installed updates

Code:

Get-WUHistory -Last 10

Motivation:

This variation is handy when you need a quick overview of only the most recent updates, such as when troubleshooting a problem that may have arisen due to a recent change or checking the latest updates installed for compliance purposes.

Explanation:

  • -Last 10: This parameter limits the output to the last ten updates, sorted by the date of installation, providing a concise list of recent update activities. This is useful for not overwhelming the user with too much historical data when only recent actions are relevant.

Example Output:

Date       Time       Status   Title
----       ----       ------   -----
10/10/2023 03:15 PM   Succeeded Security Update for Windows (KB1234567)
10/09/2023 01:00 PM   Succeeded Cumulative Update for Windows (KB8901345)
10/05/2023 02:30 AM   Succeeded Update for Microsoft Defender (KB6789012)
...

Use case 3: List all updates installed from a specific date to today

Code:

Get-WUHistory -MaxDate "2023-09-01"

Motivation:

This use case is applicable for organizations or users who need to track changes and updates over a specific period, for instance, as part of monthly report preparation or policy compliance audit, ensuring all systems are updated and protected.

Explanation:

  • -MaxDate "2023-09-01": This argument filters the update history, displaying only those updates installed from September 1, 2023, onwards. This helps narrow down the data to relevant timeframes instead of trawling through a full list.

Example Output:

Date       Time       Status   Title
----       ----       ------   -----
10/09/2023 01:00 PM   Succeeded Cumulative Update for Windows (KB8901345)
09/20/2023 05:30 AM   Succeeded Security Update for Adobe Flash Player (KB7890123)
09/15/2023 11:45 PM   Succeeded Update for Windows Antivirus (KB3456789)

Use case 4: List all updates installed in the past 24 hours

Code:

Get-WUHistory -MaxDate (Get-Date).AddDays(-1)

Motivation:

This scenario is particularly helpful for administrators needing immediate knowledge of the most recent updates for new system evaluations or post-update impact assessments, allowing quick identification of changes made within the last day.

Explanation:

  • (Get-Date).AddDays(-1): This PowerShell expression dynamically calculates the date for 24 hours ago from the current time. -MaxDate uses this calculated date to filter updates installed in the last day. This ensures the user receives the most recent changes quickly and accurately.

Example Output:

Date       Time       Status   Title
----       ----       ------   -----
10/10/2023 03:15 PM   Succeeded Security Update for Windows (KB1234567)

Use case 5: Send the results via email (SMTP)

Code:

Get-WUHistory -SendReport -PSWUSettings @{
    SmtpServer="smtp.example.com"; 
    Port=587; 
    From="admin@example.com"; 
    To="it-team@example.com"
}

Motivation:

Automating update reports is beneficial for IT teams and administrators by distributing update history via email for logging or review purposes. It ensures key stakeholders are informed of system update activities without needing direct system access.

Explanation:

  • -SendReport: Directs the command to send its output to an email recipient.
  • -PSWUSettings @{...}: A set of properties defining the email server and message details. SmtpServer specifies the mail server address, Port defines the communication port, From is the sender’s email address, and To states the recipient’s email address.

Example Output:

An email is sent with the subject “Windows Update History Report,” including the output data, appearing similarly to other listed examples but formatted for email.

Conclusion:

The Get-WUHistory command offers substantial utility for system administrators and end-users through its diverse filtering and output options. It supports informed decision-making by providing insight into when and what updates were applied, identifying potential issues, and maintaining compliance through audit trails. Its reporting features further enhance its value by simplifying data sharing among team members or stakeholders.

Related Posts

How to Use the Command 'antibody' (with Examples)

How to Use the Command 'antibody' (with Examples)

Antibody is a lightning-fast shell plugin manager designed for use with Zsh.

Read More
How to Use the Command 'mocp' (with Examples)

How to Use the Command 'mocp' (with Examples)

Music on Console (MOC) is a lightweight and flexible audio player designed for use directly from the command line.

Read More
How to use the command 'kitty' (with examples)

How to use the command 'kitty' (with examples)

Kitty is a fast, feature-rich terminal emulator designed to leverage the power of the GPU for an enhanced computing experience.

Read More