How to use the command Get-WUHistory (with examples)
- Windows
- December 25, 2023
The Get-WUHistory command is part of the external PSWindowsUpdate module and is used to retrieve the history of installed updates from Windows Update. It can only be run under PowerShell and provides information about the updates installed on a system.
Use case 1: Get list of update history
Code:
Get-WUHistory
Motivation: This use case allows you to quickly view the entire update history on your system. It can be useful to keep track of the updates that have been installed and to identify any issues related to specific updates.
Explanation: The command Get-WUHistory
retrieves the entire update history. By executing this command, you will get a list of all updates that have been installed on your system.
Example output:
ComputerName OperationCategory Operation Result Date
------------ ----------------- --------- ------ ----
Computer1 Install Update Installed Success 01/03/2022
Computer1 Install Update Installed Success 12/31/2021
Computer1 Install Update Installed Success 12/28/2021
Use case 2: List the last 10 installed updates
Code:
Get-WUHistory -Last 10
Motivation: This use case allows you to view the most recent updates that have been installed on your system. It can help you stay up to date with the latest changes and improvements.
Explanation: The command Get-WUHistory -Last 10
retrieves the last 10 installed updates. By specifying the -Last
parameter followed by the desired number of updates (in this case, 10), you will get a list of the 10 most recent updates installed on your system.
Example output:
ComputerName OperationCategory Operation Result Date
------------ ----------------- --------- ------ ----
Computer1 Install Update Installed Success 01/03/2022
Computer1 Install Update Installed Success 12/31/2021
Computer1 Install Update Installed Success 12/28/2021
...
Use case 3: List all updates installed from a specific date to today
Code:
Get-WUHistory -MaxDate "2022-01-01"
Motivation: This use case allows you to find updates that have been installed within a specific date range. It can be useful when troubleshooting issues related to recent updates.
Explanation: The command Get-WUHistory -MaxDate date
retrieves all updates installed from a specific date to today. By specifying the -MaxDate
parameter followed by the desired date (in this case, “2022-01-01”), you will get a list of updates installed from that date up to the present day.
Example output:
ComputerName OperationCategory Operation Result Date
------------ ----------------- --------- ------ ----
Computer1 Install Update Installed Success 01/03/2022
...
Use case 4: List all updates installed in the past 24 hours
Code:
Get-WUHistory -MaxDate (Get-Date).AddDays(-1)
Motivation: This use case allows you to quickly find updates that have been installed within the last 24 hours. It can be useful to identify any recent updates that may have caused issues on your system.
Explanation: The command Get-WUHistory -MaxDate (Get-Date).AddDays(-1)
retrieves all updates installed in the past 24 hours. By specifying the -MaxDate
parameter followed by the result of the (Get-Date).AddDays(-1)
expression, you will get a list of updates installed within the last 24 hours.
Example output:
ComputerName OperationCategory Operation Result Date
------------ ----------------- --------- ------ ----
Computer1 Install Update Installed Success 01/03/2022
...
Use case 5: Send the results via email (SMTP)
Code:
Get-WUHistory -SendReport -PSWUSettings @{SmtpServer="smtp_server"; Port=smtp_port; From="sender_email"; To="receiver_email"}
Motivation: This use case allows you to automatically send the results of the Get-WUHistory command via email. It can be useful when you want to share the update history with others or keep a record of it for future reference.
Explanation: The command Get-WUHistory -SendReport -PSWUSettings @{SmtpServer="smtp_server"; Port=smtp_port; From="sender_email"; To="receiver_email"}
sends the results of the Get-WUHistory command via email. By specifying the -SendReport
parameter and providing the required SMTP settings (SmtpServer
, Port
, From
, and To
), you can send the update history as an email.
Example output: N/A (The output will be sent via email)
Conclusion:
The Get-WUHistory command provides a convenient way to retrieve and analyze the update history of a Windows system. By using different parameters, you can customize the output and narrow down the results to specific time periods or send them via email for further analysis or record-keeping.