Using DevCon utility, I ran this command to get the list of all of the drivers installed in the computer.
devcon.exe driverfiles * > drivers.txt
The output looks like this:
USB\ROOT_HUB20\4&361B340A&0
Name: USB Root Hub
Driver installed from C:\windows\INF\usbport.inf [ROOTHUB.Dev]. 2 file(s) used by driver:
C:\windows\system32\drivers\usbhub.sys
C:\windows\system32\drivers\usbd.sys
ACPI\PNP0C09\1
USB\ROOT_HUB20\4&361B340A&1
Name: USB Root Hub
Driver installed from C:\windows\INF\usbport.inf [ROOTHUB.Dev]. 2 file(s) used by driver:
C:\windows\system32\drivers\usbhub.sys
C:\windows\system32\drivers\usbd.sys
I then used PowerShell script to parse the file. Thanks to TheMadTechnician.
(Get-Content C:\Path\To\File.txt) -join "`r`n" -Split "(?m)^(?=\S)" |
Where{$_} |
ForEach{
Clear-Variable Files,Driver,Name,HardwareID
$Files = @()
$HardwareID = ($_ -split "`r`n")[0].trim()
Switch -regex ($_ -split "`r`n"){
"^\s+Name:" {$Name = ($_ -split ':',2)[-1].trim();Continue}
"^\s+.:\\" {$Files += $_.trim();continue}
"^\s+Driver" {$Driver = [RegEx]::Matches($_,"(?<=Driver installed from )(.+?)(?= \[)").value;continue}
}
[PSCustomObject]@{'HardwareID' = $HardwareID;'Name' = $Name; 'Files' = $Driver; 'FileVersion' = If(Test-Path $_.Trim()){[System.Diagnostics.FileVersionInfo]::GetVersionInfo($_.trim()).FileVersion}}
$Files | ForEach{ [PSCustomObject]@{'HardwareID' = $HardwareID;'Name' = $Name; 'Files' = $_; 'FileVersion' = If(Test-Path $_.Trim()){[System.Diagnostics.FileVersionInfo]::GetVersionInfo($_.trim()).FileVersion}Else{'File Not Found'}}}
Now, the output after running the script is:
HardwareID Name Files FileVersion
---------- ---- ----- -----------
USB\ROOT_HUB20\4&361B340A&0 USB Root Hub C:\windows\INF\usbport.inf
USB\ROOT_HUB20\4&361B340A&0 USB Root Hub C:\windows\system32\drivers\usbhub.sys 6.3.9600.17238 (winblue_gdr.140723-2018)
USB\ROOT_HUB20\4&361B340A&0 USB Root Hub C:\windows\system32\drivers\usbd.sys 6.3.9600.17195 (winblue_gdr.140530-1506)
ACPI\PNP0C09\1
USB\ROOT_HUB20\4&361B340A&1 USB Root Hub C:\windows\INF\usbport.inf
USB\ROOT_HUB20\4&361B340A&1 USB Root Hub C:\windows\system32\drivers\usbhub.sys 6.3.9600.17238 (winblue_gdr.140723-2018)
USB\ROOT_HUB20\4&361B340A&1 USB Root Hub C:\windows\system32\drivers\usbd.sys 6.3.9600.17195 (winblue_gdr.140530-1506)
THE PROBLEM
I would like to add an extra column with driver version.
How can I find the driver version and list it next to the name column? Thank you!
EDIT
The code below parses driver version from the INF file. I am not experienced with PowerShell, so how can I used this bit of information and incorporate it with the above code to add an extra column and list driver version; preferably, next to Name column.
$pattern = 'DriverVer\s*=\s*(?:\d+/\d+/\d+,)?(.*)'
Select-String -Pattern $pattern -Path $path |
select -Expand Matches -First 1 |
% { $_.Groups[1].Value }
# $path = the INF file
[PSCustomObject]line in your script.devcon.exe drivernodesto list the version. But that would be a second command; hence, separate file(not sure if I can use and out in DevCon). Is there way to user PS command during parsing to find the version?[PSCustomObject]what param would give the driver version?[PSCustomObject]line). But rather than just feeding you the answer this time, I'll give you what you need to do this yourself with a little effort. Look intoSelect-String, and theLineproperty that it outputs. Then use the[RegEx]::Matchesmethod I used above with "(?<=,)(.*)$" as your match string. Come back with an error if you try and fail.Get-WindowsDriverinstead of having to parse through the inf file.[PSCustomObject]can be tweaked to print it out in the column.