title: PowerShell Find Driver Version
body: <p>Using DevCon utility, I ran this command to get the list of all of the drivers installed in the computer.</p>
  
  <pre><code>devcon.exe driverfiles * &gt; drivers.txt
  </code></pre>
  
  <p>The output looks like this:</p>
  
  <pre><code>USB\ROOT_HUB20\4&amp;361B340A&amp;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&amp;361B340A&amp;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
  </code></pre>
  
  <p>I then used PowerShell script to parse the file. Thanks to TheMadTechnician.</p>
  
  <pre><code>(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($_,"(?&lt;=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'}}}
  </code></pre>
  
  <p>Now, the output after running the script is:</p>
  
  <pre><code>HardwareID                  Name                                            Files                                  FileVersion                             
  ----------                  ----                                            -----                                  -----------                             
  USB\ROOT_HUB20\4&amp;361B340A&amp;0 USB Root Hub                                    C:\windows\INF\usbport.inf                                                     
  USB\ROOT_HUB20\4&amp;361B340A&amp;0 USB Root Hub                                    C:\windows\system32\drivers\usbhub.sys 6.3.9600.17238 (winblue_gdr.140723-2018)
  USB\ROOT_HUB20\4&amp;361B340A&amp;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&amp;361B340A&amp;1 USB Root Hub                                    C:\windows\INF\usbport.inf                                                     
  USB\ROOT_HUB20\4&amp;361B340A&amp;1 USB Root Hub                                    C:\windows\system32\drivers\usbhub.sys 6.3.9600.17238 (winblue_gdr.140723-2018)
  USB\ROOT_HUB20\4&amp;361B340A&amp;1 USB Root Hub                                    C:\windows\system32\drivers\usbd.sys   6.3.9600.17195 (winblue_gdr.140530-1506)
  </code></pre>
  
  <p><strong>THE PROBLEM</strong></p>
  
  <p>I would like to add an extra column with driver version. </p>
  
  <p>How can I find the driver version and list it next to the name column? Thank you!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>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.</p>
  
  <pre><code>$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
  </code></pre>