Private/Get-OSDDrivers.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function Get-OSDDrivers {
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory)]
        [string]$WorkspacePath,

        [Parameter(Mandatory)]
        [ValidateSet ('GetAmdPack','TestAmdPack')]
        $Action
    )

    $OSDWorkspace = Get-PathOSDD -Path $WorkspacePath
    Write-Verbose "Workspace Path: $OSDWorkspace" -Verbose

    $WorkspaceDownload = Get-PathOSDD -Path (Join-Path $OSDWorkspace 'Download')
    Write-Verbose "Workspace Download: $WorkspaceDownload" -Verbose

    $WorkspaceExpand = Get-PathOSDD -Path (Join-Path $OSDWorkspace 'Expand')
    Write-Verbose "Workspace Expand: $WorkspaceExpand" -Verbose
    $WorkspacePackages = Get-PathOSDD -Path (Join-Path $OSDWorkspace 'Packages')
    Write-Verbose "Workspace Packages: $WorkspacePackages" -Verbose

    if ($Action -eq 'GetAmdPack') {
        $AmdInfs = @()
        if (Test-Path "$WorkspaceExpand\HpModel") {
            Write-Verbose "Searching for AMD Video Drivers in $WorkspaceExpand\HpModel" -Verbose
            $AmdInfs = Get-ChildItem "$WorkspaceExpand\HpModel" *.inf -Recurse | Where-Object {$_.FullName -match '\\graphics\\amd\\' -and $_.FullName -notmatch '\\audio\\'} | Select-Object FullName
        }
        $AmdList = @()
        foreach ($AmdInf in $AmdInfs) {
            $AmdList += Get-WindowsDriver -Online -Driver "$($AmdInf.FullName)" | Select-Object -Property * #HardwareId, HardwareDescription, Version, Driver, ClassName
        }
        foreach ($Pnp in $AmdList) {
            $Pnp.HardwareId = ($Pnp.HardwareId -split '\&REV')[0]
        }
        $AmdList = $AmdList | Where-Object {$_.ClassName -eq 'Display'} | Sort-Object HardwareId -Unique #| Select-Object HardwareId, HardwareDescription

        Write-Verbose "AMD Video List saved as $OSDWorkspace\AmdPack.csv" -Verbose
        $AmdList | ConvertTo-Csv -NoTypeInformation | Set-Content -Path "$OSDWorkspace\AmdPack.csv"

        Write-Verbose "AMD Video Object saved as $OSDWorkspace\AmdPack.clixml" -Verbose
        $AmdList | Export-Clixml "$OSDWorkspace\AmdPack.clixml"
    }

    if ($Action -eq 'TestAmdPack') {
        $AmdList = @()
        if (Test-Path "$OSDWorkspace\AmdPack.clixml") {
            $AmdList = Import-Clixml "$OSDWorkspace\AmdPack.clixml" | Where-Object {$_.HardwareId -match 'PCI\\VEN_1002'}
            Write-Host ""
            Write-Host "$($AmdList.Count) Amd Video Devices from Hp Model Packs" -ForegroundColor Green
            Write-Host ""
            $AllDrivers = @()
            $DriverPnps = Get-ChildItem "$WorkspacePackages\AmdPack 10.0 x64" *.drvpnp -Recurse | Select-Object BaseName, FullName | Sort-Object BaseName -Descending | Out-Gridview -PassThru -Title 'Select Amd Drivers to Evaluate'
        
            foreach ($DriverPnp in $DriverPnps) {
                $Title = $DriverPnp.BaseName
                Write-Host "Evaluating: $Title" -Foregroundcolor Green
            
                $MatchingDriver = @()
                $NotMatchingDriver = @()
                $Drivers = @()
                $Drivers = Import-Clixml $DriverPnp.FullName
            
                foreach ($Hardware in $AmdList) {
                    $DriverMatch = $false
                    foreach ($Driver in $Drivers) {
                        if ($Hardware.HardwareId -like "*$($Driver.HardwareId)*") {
                            $DriverMatch = $true
                            Continue
                        }
                    }
                    if ($DriverMatch -eq $true) {$MatchingDriver += $Hardware}
                    if ($DriverMatch -eq $false) {$NotMatchingDriver += $Hardware}
                }
                
                Write-Host "$($MatchingDriver.Count) Devices are supported by this Driver" -ForegroundColor Cyan
            
                $AmdList = $NotMatchingDriver
                Write-Host "$($NotMatchingDriver.Count) Remaining Devices" -ForegroundColor Cyan
                Write-Host ""
            }
        
            $AmdList = $AmdList | Sort HardwareId -Unique | Select HardwareId, HardwareDescription, Driver
            $UniqueResults = ($AmdList).count
            Write-Host "$UniqueResults AMD Video Devices without a Driver" -ForegroundColor Green
            
            $AmdList | Export-Clixml "$OSDWorkspace\AmdPack-Results.clixml"
            $AmdList | Out-GridView -Title "Remaining HardwareID's that need Drivers"
        }
    }
}