Get System Insall

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 6 years, 2 months ago.

  • Author
  • #5729

    by jeg at 2013-03-27 14:47:16

    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\admin\Desktop\PS\GetInstallDate.ps1:38 char:3
    + $Report.InstallDate = [datetime] (Get-WmiObject -Class Win32_OperatingSystem – ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastParseTargetInvocationWithFormatProvider

    by ps_gregg at 2013-03-28 17:22:18

    Hi Jeg,

    WMI handles dates differently and you will need to use the ConvertToDateTime Method of the WMI object.
    I recommend that you change line #38

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

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

    Hope that helps.


You must be logged in to reply to this topic.