powershellwmiwmi-querypowershell-5.1cim

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


In the Device Manager, I can view the properties of any device (disk drives included). In the Details tab, I can select the first install date:

enter image description here

In PowerShell, I can get all disk drives by issuing:

Get-CimInstance -ClassName CIM_DiskDrive

The returned objects have an InstallDate property, but it is empty. How can I get the date, that is visible in the device manager, in PowerShell? Do I have to associate the CIM_DiskDrive class with another CIM class? If so, which?


Solution

  • With the excellent pointer from Almighty's answer I came up with the following solution:

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

    It gets all currently installed disk drives and returns their friendly names and first install dates as a custom object for further processing.