Get the Windows Install Date of a remote computer with PowerShell

A quick script that came up in response to a situation where I wanted to know the date a workstation on the network was last built without visiting the machine or interrupting the currently logged on user. PowerShell to the rescue!

The WMI property “InstallDate” comes into play here.

(Get-WmiObject Win32_OperatingSystem).InstallDate

Returns a date: “20180717202039.000000+060” for my workstation. The Get-WmiObject cmdlet can again be leveraged to make this into a more usable PowerShell DateTime object:

(Get-WmiObject Win32_OperatingSystem).ConvertToDateTime( (Get-WmiObject Win32_OperatingSystem).InstallDate )

Which returns 17 July 2018 20:20:39.

Get-WmiObject can also be used on a remote computer, this example would return the date that the computer called WS12000 was built.

(Get-WmiObject win32_OperatingSystem –ComputerName “WS12000”).InstallDate

I’ve taken this work and expanded it into a PowerShell function (available on GitHub). This function “Get-BuildDate” takes one or more computer names and returns a table of build dates and, because it’s handy, the number of days that have passed since that date.

Some example usage would be:

Return the installation date of workstation 40200:

Get-BuildDate  -ComputerNames "WS40200"

Computer BuildDate           DaysSinceLastBuild
-------- ---------           ------------------
WS40200  17/07/2018 20:20:39                 55

Return the installation date of workstations WS40200 and WS46000:

Get-BuildDate ("WS40200","WS46000")

or alternatively using pipeline input:

("WS40200","WS46000") | Get-BuildDate

Finally, return a table of the last build dates for the sequentially numbered computers called WS12300, WS12301, WS12302…. right through to WS12399:

$Computers=((12300..12399) | ForEach-Object{ "WS$_"}) | Get-BuildDate

The script (and any future refinements) is available here: https://github.com/isjwuk/powershell-general/blob/master/Get-BuildDate.ps1

Leave a Reply

Your email address will not be published. Required fields are marked *