Windows Updates are part of every admins monthly task list. This is to firstly test if you can in a lab what the updates fix but also what potential issues may arise from the new Windows Updates. On Windows Server GUI (Graphical User Interface) you can go to Settings and then Windows updates and get a list of installed updates or failed ones, however on Server Core it is a different task as you do not have a GUI.

In legacy versions of the Windows Operating System, you could identify when an update was installed easier than newer versions. I wanted to know when updates were installed on my Lab Exchange 2019 Servers that are on Windows Server Core along with the time stamp so I put together a small script to achieve this.

In the snippet below, you can see the server name along with the date and time of the last Windows Updates Installation:

Quickly find when updates were installed on a server with powershell

SCRIPT

The script needs to be updated on Line 2 with the computers you want to check:

  • $computers – Type in the computer names, separated by a comma

Here is the script that you can use:

# Array of computer names or IP addresses
$computers = @("exch1", "exch2", "exch3")

foreach ($computer in $computers) {
    try {
        # Get the last Windows Update installation date and time
        $lastUpdate = Invoke-Command -ComputerName $computer -ScriptBlock {
            $windowsUpdateLog = Get-Item "$env:SystemRoot\WindowsUpdate.log"
            $windowsUpdateLog.LastWriteTime
        }

        # Display the last Windows Update installation date and time for the current computer
        Write-Host "Last Windows Update installation time on $computer : $($lastUpdate)"
    } catch {
        Write-Host "Error retrieving information from $computer : $_"
    }
}

This script was tested on Server 2019 Core and Server 2022 GUI, using PowerShell ISE and normal Windows PowerShell.

Hope you find it helpful.

    wpChatIcon

    Discover more from Everything-PowerShell

    Subscribe now to keep reading and get access to the full archive.

    Continue reading