簡體   English   中英

如何獲取 PowerShell 中磁盤驅動器的首次安裝日期?

[英]How do I get the first install date of a disk drive in PowerShell?

設備管理器中,我可以查看任何設備(包括磁盤驅動器)的屬性。 詳細信息選項卡中,我可以 select首次安裝日期

在此處輸入圖像描述

在 PowerShell 中,我可以通過發出以下命令獲取所有磁盤驅動器:

Get-CimInstance -ClassName CIM_DiskDrive

返回的對象具有InstallDate屬性,但它是空的。 如何在 PowerShell 中獲取在設備管理器中可見的日期? 我是否必須將CIM_DiskDrive class 與另一個 CIM class 相關聯? 如果是這樣,哪個?

使用Get-PnpDeviceProperty您可以提取您正在尋找的附加信息。 它不像你想象的那么直觀,但它確實有效,我相信你可以找到確切的 Class 並直接拉取它。 但這是一種功能性方式 n.netheless。

# Get PNPDeviceID from the disk driver
$PNPDeviceID = Get-CimInstance -ClassName CIM_DiskDrive | Select-Object -ExpandProperty PNPDeviceID

# Get friendly name to verify and first install date
Get-PnpDeviceProperty -InstanceId $PNPDeviceID -KeyName DEVPKEY_Device_FriendlyName, DEVPKEY_Device_FirstInstallDate | Select-Object KeyName, Data

憑借Almighty 的回答中的出色指示,我想出了以下解決方案:

Get-PnpDevice -Class DiskDrive -Status OK | ForEach-Object {
    [PSCustomObject]@{
        FriendlyName=(Get-PnpDeviceProperty -InputObject $_ -KeyName DEVPKEY_Device_FriendlyName).Data;
        FirstInstallDate=(Get-PnpDeviceProperty -InputObject $_ -KeyName DEVPKEY_Device_FirstInstallDate).Data
    }
}

它獲取所有當前安裝的磁盤驅動器並返回它們的友好名稱和首次安裝日期作為自定義 object 以供進一步處理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM