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.
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:
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.
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:
Computer BuildDate DaysSinceLastBuild
-------- --------- ------------------
WS40200 17/07/2018 20:20:39 55
Return the installation date of workstations WS40200 and WS46000:
or alternatively using pipeline input:
Finally, return a table of the last build dates for the sequentially numbered computers called WS12300, WS12301, WS12302…. right through to WS12399:
The script (and any future refinements) is available here: https://github.com/isjwuk/powershell-general/blob/master/Get-BuildDate.ps1