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.

1(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:

1(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.

1(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:

1Get-BuildDate  -ComputerNames "WS40200"
2
3Computer BuildDate           DaysSinceLastBuild
4-------- ---------           ------------------
5WS40200  17/07/2018 20:20:39                 55

Return the installation date of workstations WS40200 and WS46000:

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

or alternatively using pipeline input:

1("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:

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

The script (and any future refinements) is available here: github.com/isjwuk/powershell-general/