PoshCode Archive  Artifact [7256f63f86]

Artifact 7256f63f86330ee81e8fbcfe35212c39f94134dd9ab9a26df6cf68b12edcecd6:

  • File Get-SystemInstallDate.ps1 — part of check-in [8252bddeb0] at 2018-06-10 13:47:10 on branch trunk — From gregs repository on github. (user: greg zakharov size: 1029)

# encoding: ascii
# api: powershell
# title: Get-SystemInstallDate
# description: From greg’s repository on github.
# version: 0.1
# type: function
# author: greg zakharov
# license: CC0
# function: Get-SystemInstallDate
# x-poshcode-id: 4868
# x-archived: 2014-02-09T09:49:55
# x-published: 2014-02-03T13:50:00
#
#
#requires -version 2.0
function Get-SystemInstallDate([String]$Computer = '.') {
  <#
    .NOTES
        Author: greg zakharov
  #>
  
  try {
    [Management.ManagementDateTimeConverter]::ToDateTime(
      ((New-Object Management.ManagementClass(
        [Management.ManagementPath]('\\' + $Computer + '\root\cimv2:Win32_OperatingSystem')
      )).PSBase.GetInstances() | select InstallDate).InstallDate
    )
  }
  catch [Management.Automation.MethodInvocationException] {
    if ($_.Exception) {
      [TimeZone]::CurrentTimeZone.ToLocalTime([DateTime]'1.1.1970').AddSeconds(
        (gp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').InstallDate
      )
    }
  }
}