Search code examples
windowspowershelldateoperating-systemsysinfo

Listing system information in convenient format using Powershell


I hope someone can help me. I'm currently genertating a list of computer dates to see which need to be replaced (>3 years).

Is it possible to echo this in a csv or excel?

I made the following snippet:

 $env:COMPUTERNAME
 $ComputerSystem = Get-WmiObject  -Class Win32_ComputerSystem
 $BIOS = Get-WmiObject  -Class Win32_BIOS
 $BIOSageInYears = (New-TimeSpan -Start ($BIOS.ConvertToDateTime($BIOS.releasedate).ToShortDateString()) -End $(Get-Date)).Days / 365
 $OperatingSystem = Get-WmiObject  -Class Win32_OperatingSystem
 $OSInstallDate = ($OperatingSystem.ConvertToDateTime($OperatingSystem.InstallDate).ToShortDateString())
 $System.SerialNumber
 $ComputerSystem.Manufacturer
    $ComputerSystem.Model
    ($BIOS.ConvertToDateTime($BIOS.releasedate).ToShortDateString())
    $BIOSageInYears
    $OS=@(Get-ChildItem -Path HKLM:\System\Setup\Source* | ForEach-Object {Get-ItemProperty -Path Registry::$_}; Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion')
    $OS | Select-Object ProductName, ReleaseID, CurrentBuild, @{Name='InstallDate'; Expression={[timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($_.InstallDate))}} | Sort-Object "InstallDate"

This gives me the following output:

PS U:\> U:\build.ps1
WS0***MH
Hewlett-Packard
HP Z440 Workstation
08-11-2017
3.81095890410959

ProductName                     ReleaseId CurrentBuild InstallDate        
-----------                     --------- ------------ -----------        
Windows 10 Pro for Workstations 1709      16299        19-04-2018 13:38:08
Windows 10 Pro for Workstations 1803      17134        03-05-2018 10:25:24
Windows 10 Pro for Workstations 1909      18363        05-07-2019 10:52:48
Windows 10 Pro for Workstations 2009      19043        14-06-2021 17:11:32

So i want the first installed date and date in years in my output. At the moment it only works for the bios date.

I just need this

WS0***MH
Hewlett-Packard
HP Z440 Workstation
19-04-2018 13:38:08 (first installed date - NOT Bios)
3.81095890410959 (age first installed - NOT Bios)

Solution

  • The first setup date of Windows 10 is hard to find in a reliable way. One way is to check the modify date of the Client Side Cache folder...

    $ComputerSystem = Get-CimInstance  -Class Win32_ComputerSystem
     
    $SystemInfo = New-Object PSCustomObject | Select ComputerName,Manufacturer,Model,FirstSetup,SetupAge
        $SystemInfo.ComputerName = $env:COMPUTERNAME
        $SystemInfo.Manufacturer = $ComputerSystem.Manufacturer
        $SystemInfo.Model = $ComputerSystem.Model
        $SystemInfo.FirstSetup = (get-item c:\windows\csc).LastWriteTime
        $SystemInfo.SetupAge = ((get-date) - $SystemInfo.FirstSetup).Days / 365
    
    $SystemInfo | Export-Csv SystemInfo.csv
    

    You might wan't to change the output format of $SystemInfo.FirstSetup to something other then system locale.