# 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
)
}
}
}