0

Please help me in solving non-standard tasks (Powershell). Need to read *.inf files: C:\Windows\System32\DriverStore\FileRepository" and to bring to the table: Manufacter, DeviceID, VerDRV.

ls "C:\Windows\System32\DriverStore\FileRepository" -Recurse -File -Filter *.inf | %{

$mtch = $_ |Select-String -AllMatches -Pattern "^\[(.+)\]$|^([^;].+)=(.+[^;])"
$infObj = New-Object pscustomobject
$mtch.Matches | % {
if ($_.Groups[1].Success) {
    $section = $_.Groups[1].Value
    Add-Member -InputObject $infObj -MemberType NoteProperty -Name $section -Value (New-Object pscustomobject)
} else {
    Add-Member -InputObject $infObj.$section -MemberType NoteProperty -Name $_.Groups[2].Value -Value $_.Groups[3].Value
}
}



$infObj.Version |  Format-Table
$infObj = $null
$mtch = $null
$section = $null }

Grateful for the help.

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206

2 Answers2

0

I wrote a function called Invoke-InstallDrivers (Link to Github) which was created to compare the GUID of the driver file to the GUID's of the installed hardware, if there was a match it would install, if there wasn't a match it would skip. Basically I modified that function a bit to pull the data you are looking for, however, I found that several of the .INF files at the location you specified do not contain a "manufacturer" value so I added some logic to state if there is no value. Lastly, I don't see any DeviceID fields in any inf files located at that path on my test workstation so I assumed ClassGUID is what you are referring to.

Function Get-DriverInfo {

       [CmdletBinding()]
        param(

            [Parameter(Mandatory=$true)]
            [String[]] $Source

         )

    $Drivers = Get-ChildItem -Path "$Source\*" -Recurse | Where {$_.Extension -eq ".inf"} | Select -ExpandProperty FullName  

    Foreach ($Driver in $Drivers)
        {
            Write-Output "Processing File: $Driver"
            $GUID = (Get-Content -Path "$Driver" | Select-String "ClassGuid").Line.Split('=')[-1].Split(' ').Split(';')
            $Version = (Get-Content -Path "$Driver" | Select-String "DriverVer").Line.Split('=')[-1].Split(' ').Split(';')

            if ((Get-Content -Path "$Driver" | Select-String "MfgName") -eq $null)

                {
                    $Manufacturer = "No Manufactuer Listed in INF"
                }

            ELSE

                {
                    $Manufacturer = (Get-Content -Path "$Driver" | Select-String "MfgName").Line.Split('=')[-1].Split(' ').Split(';')
                }

            Write-Output "$Manufacturer, $Version, $GUID"
        }

}

You would use the above function by running:

Get-DriverInfo -Source "C:\Windows\System32\DriverStore\FileRepository"

You may need to tweak output formatting to your preference but this should put you on the right path to solving your issue.

Edit Thought I would add what the output will look like, first part shows inf with manufacturer and other shows without manufacturer (paths were shortened for readability):

PS C:\> Get-DriverInfo -Source "C:\Windows\System32\DriverStore\FileRepository"
Processing File: C:\Windows\System32\DriverStore\FileRepository\...\bcbtumsLD.inf
"Broadcom", 09/25/2013,6.5.1.4800, {e0cbf06c-cd8b-4647-bb8a-263b43f0f974} 

Processing File: C:\Windows\System32\DriverStore\FileRepositor\...\bcmhidnossr.inf 
No Manufactuer Listed in INF, 03/28/2013,1.0.0.101, {745a17a0-74d3-11d0-b6fe-00a0c90f57da}

Hope this helps!

Tyler Helder
  • 594
  • 3
  • 11
  • Cool, but not suitable. :( I think If not the Manufacturer, skip the result. About the GUID, I mean model. For example Manufacter = "HP", Model = "HP Photosmart 2570" or "HP Color LaserJet 2820" (never mind) DriverVer = "6.1.7600.16385" – Kolba-ba-soid Jun 13 '16 at 09:34
  • Sound like you are asking for something that isn't possible. Other than the version and manufacturer listed in my above output your not going to be able to pull that any differently. Lastly model isn't typically in the driver setup file (inf) as the driver could apply to a broad set of hardware. You can open the inf files in notepad ++ or something similar to see what information they contain. Cant get information that isn't there. – Tyler Helder Jun 13 '16 at 14:55
  • Exactly! I need all Models from *.inf. In the end make a table that will list the Manufacturers, all possible model and driver version. – Kolba-ba-soid Jun 14 '16 at 04:36
0

Thanks to all! Special thanks to Pavel Pakhomov :)

Clear-Host
Get-ChildItem "C:\Windows\System32\DriverStore\FileRepository" -Recurse -File -Filter '*.inf' | ForEach-Object {
    $fileContent = Get-Content $_.FullName
    #write-host ">>>>>" + $_.FullName

    $dirverVer = ($fileContent | Select-String -SimpleMatch 'DriverVer=') -replace '.*=(.*)','$1'
    #$Provider = ($fileContent | Select-String -SimpleMatch 'Provider=') -replace '.*=(.*)','$1'
    $Provider = ($fileContent | Select-String '^\s*Provider\s*=.*') -replace '.*=(.*)','$1'
    if ($Provider.Length -eq 0) {
        $Provider = ""
    }
    elseif($Provider.Length -gt 0 -And $Provider -is [system.array]) {
        if ($Provider.Length -gt 1 -And $Provider[0].Trim(" ").StartsWith("%")) {
            $Provider = $Provider[1];
        } else {
            $Provider = $Provider[0]
        }
    }
    $Provider = $Provider.Trim(' ')

    if ($Provider.StartsWith("%")) {
        $Provider = $Provider.Trim('%')
        #$Manufacter = ($fileContent | Select-String -SimpleMatch "%$Provider2%=") -replace '.*=(.*)','$1'
        $Manufacter = ($fileContent | Select-String "^$Provider\s*=") -replace '.*=(.*)','$1'
    }
    else {
        $Manufacter = ""
    }    

    $ClassGUID = ($fileContent | Select-String -SimpleMatch 'ClassGUID=') -replace '.*=(.*)','$1'

    if ($Manufacter.Length -eq 0) {
        $Manufacter = $Provider
    } elseif ($Manufacter.Length -gt 0 -And $Manufacter -is [system.array]) {
        if ($Manufacter.Length -gt 1 -And $Manufacter[0].Trim(" ").StartsWith("%")) {
            $Manufacter = $Manufacter[1];
        }
        else {
            $Manufacter = $Manufacter[0];
        }
    }
    $Manufacter = $Manufacter.Trim(' ').Trim('"')

    New-Object -TypeName psobject -Property @{
        Name = $_.Name
        Manufacturer = $Manufacter
        GUID = $ClassGUID
        Version = $dirverVer
    }
} | Format-Table -Property Name,Manufacturer,GUID,Version