【问题标题】:Listing system information in convenient format using Powershell使用 Powershell 以方便的格式列出系统信息
【发布时间】:2021-10-29 01:33:41
【问题描述】:

我希望有人可以帮助我。我目前正在生成一个计算机日期列表,以查看哪些需要更换(>3 年)。

是否可以在 csv 或 excel 中回显此内容?

我做了以下sn-p:

 $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"

这给了我以下输出:

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

所以我想要输出中的第一个安装日期和年份。目前它仅适用于 bios 日期。

我只需要这个

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)

【问题讨论】:

  • 查看Get-ComputerInfo cmdlet。它有一个-Property 参数,可以接受您想要的道具列表......或者您可以忽略不需要的道具。
  • 这将返回大多数信息,但不会返回第一次安装的安装日期。所以我不知道工作站有多旧。
  • 您可以使用calculated property 将该列添加到您的输出中。
  • @Lucas - 正如 Bill_Stewart 指出的那样,您始终可以使用计算属性的某些变体来构建您已经拥有的东西。 [咧嘴]

标签: windows powershell date operating-system sysinfo


【解决方案1】:

很难以可靠的方式找到 Windows 10 的首次安装日期。一种方法是检查客户端缓存文件夹的修改日期...

$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

您可能不想将$SystemInfo.FirstSetup 的输出格式更改为系统区域设置以外的格式。

【讨论】:

    猜你喜欢
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多