Get System Install Date throws an error

by jeg at 2013-03-27 14:49:29

Running below from here: … dd84bc6239

This script gets a system installation date.
This script uses WMI to get a system installation date.
You can enter a list of computernames as a parameter.
The defaut is the current computer.
The script accepts input from the pipeline.
An object containing Computer and InstallDate properties.
File Name : Get-SystemInstallDate.ps1
Author : Robert van den Nieuwendijk
Twitter : rvdnieuwendijk
Requires : PowerShell Version 2.0
This script is posted to Microsoft TechNet Script Center Repository: … ter/en-us/
Retrieves the installation date from the current system.
C:\PS>.\Get-SystemInstallDate.ps1 -ComputerName server1,server2
Retrieves the installation date from server1 and server 2.
C:\PS>“server1”,“server2”| .\Get-SystemInstallDate.ps1
Retrieves the installation date from server1 and server 2.

param ([Parameter(ValueFromPipeline=$true)][string[]] $ComputerName = ‘.’)

begin {
function Get-SystemInstallDateForOneSystem {
param ([string] $ComputerName = ‘.’)
$Report = “” | Select-Object -property Computer,InstallDate
$Report.Computer = $ComputerName
$Report.InstallDate = [datetime] (Get-WmiObject -Class Win32_OperatingSystem -ComputerName $ComputerName).InstallDate

process {
if ($ComputerName -is [array]) {
$ComputerNames = $ComputerName
foreach ($ComputerName in $ComputerNames) {
Get-SystemInstallDateForOneSystem -ComputerName $ComputerName
else {
Get-SystemInstallDateForOneSystem -ComputerName $ComputerName

Gives me this:

Cannot convert value “20121211102032.000000-480” to type “System.DateTime”. Error: "String was not recognized as a valid
At C:\Users&lt;redacted>\Desktop\PS\GetInstallDate.ps1:38 char:3
+ $Report.InstallDate = [datetime] (Get-WmiObject -Class Win32_OperatingSystem - …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:slight_smile: [], RuntimeException
+ FullyQualifiedErrorId : InvalidCastParseTargetInvocationWithFormatProvider
by DonJ at 2013-03-28 07:51:04
So, your first bet would be to contact the poster of the script. But, in general, WMI dates are tricky to work with.

Instead of:

$Report.InstallDate = [datetime] (Get-WmiObject -Class Win32_OperatingSystem -ComputerName $ComputerName).InstallDate


$InstallDate = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $ComputerName
$Report.InstallDate = $InstallDate.ConvertToDateTime($InstallDate.InstallDate)

That’s the correct way to convert a WMI date/time to a .NET Framework DateTime object.
by OliAdams at 2013-03-28 16:20:24
I am not sure if this helps or not and I know Mr Powershell has already answered, if you use Get-CimInstance instead of Get-WmiObject this returns the date in the correct format.

PS C:&gt; Get-CimInstance win32_operatingsystem | Select InstallDate

27.01.2013 23:33:18
by jeg at 2013-04-11 07:30:10
Both of these work, thanks a TON!