简体   繁体   中英

How to get DriverDate in Readable format (mm-dd-yyyy) in powershell

I am using below command in powershell to get driver version and driver date :

Get-WmiObject Win32_PnPSignedDriver |?{$_.DeviceName -ne $null}|select DeviceName,DriverVersion,DriverDate |export-csv -path DeviceDriverVersion.csv -NoTypeInformation -Encoding UTF8

However, for DriverDate , I am getting date in such format "20060621000000.******+***" need to convert it into (mm-dd-yyyy)

Based on this article from MSDN , ConvertToDateTime from Win32_OperatingSystem could be used for parsing this date/time string, like:

$os = Get-WmiObject –Class Win32_OperatingSystem
Get-WmiObject Win32_PnPSignedDriver `
    |?{$_.DeviceName -ne $null}`
    |select DeviceName,DriverVersion,@{Label="DriverDate";Expression={$os.ConvertToDateTime($_.DriverDate).ToString("MM-dd-yyyy")}}`
    |export-csv -path DeviceDriverVersion.csv -NoTypeInformation -Encoding UTF8

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM