Public/Functions/Catalogs/Child/Get-HPOSDDriversCatalog.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<#
.SYNOPSIS
Returns a PowerShell Object of the HP Model Driver Packs
 
.DESCRIPTION
Returns a PowerShell Object of the HP Model Driver Packs by parsing the Catalog at https://ftp.hp.com/pub/caps-softpaq/cmit/HPClientDriverPackCatalog.cab"
 
.LINK
https://github.com/OSDeploy/OSD/tree/master/Docs
#>

function Get-HPOSDDriversCatalog {
    [CmdletBinding()]
    param ()
    #=================================================
    # DriverPackCatalog
    #=================================================
    $DriverPackCatalog = Import-Clixml -Path "$($MyInvocation.MyCommand.Module.ModuleBase)\Catalogs\HPDriverPackCatalog.xml"
    #=================================================
    # ForEach
    #=================================================
    $ErrorActionPreference = 'SilentlyContinue'
    $global:GetOSDDriverHpModel = @()
    $global:GetOSDDriverHpModel = foreach ($item in $DriverPackCatalog) {
        #=================================================
        # Skip
        #=================================================
        if ($item.Name -match 'IOT') {Continue}
        if ($item.Name -match 'x86') {Continue}
        if ($item.Name -match 'Win7') {Continue}
        if ($item.Name -match 'Win 7') {Continue}
        if ($item.Name -match 'Windows 7') {Continue}
        if ($item.Name -match 'Win 8') {Continue}
        if ($item.Name -match 'Windows 8') {Continue}
        #=================================================
        # Defaults
        #=================================================
        $OSDVersion = $(Get-Module -Name OSD | Sort-Object Version | Select-Object Version -Last 1).Version
        $LastUpdate = [datetime] $(Get-Date)
        $OSDStatus = $null
        $OSDType = 'ModelPack'
        $OSDGroup = 'HPModel'

        $DriverName = $null
        $DriverVersion = $null
        $DriverReleaseId = $null
        $DriverGrouping = $null

        $OperatingSystem = @()
        $OsVersion = $null
        $OsArch = $null
        $OsBuildMax = @()
        $OsBuildMin = @()

        $Make = 'HP'
        $MakeNe = @()
        $MakeLike = @()
        $MakeNotLike = @()
        $MakeMatch = @()
        $MakeNotMatch = @()

        $Generation = 'G0'
        $SystemFamily = $null

        $Model = $Item.Model
        $ModelNe = @()
        $ModelLike = @()
        $ModelNotLike = @()
        $ModelMatch = @()
        $ModelNotMatch = @()

        $SystemSku = $Item.SystemId
        $SystemSkuNe = @()

        $DriverBundle = $null
        $DriverWeight = 100

        $DownloadFile = $null
        $SizeMB = $null
        $DriverUrl = $null
        $DriverInfo = $null
        $DriverDescription = $null
        $Hash = $null
        $OSDGuid = $(New-Guid)
        #=================================================
        # Get Values
        #=================================================
        $LastUpdate = [datetime] $item.DateReleased
        $DriverName = $item.Name
        $DriverName = ($DriverName).Replace('/',' ')
        $DriverName = ($DriverName).Replace(' x64','')
        $DriverName = ($DriverName).Replace(' x86','')
        $DriverName = ($DriverName).Replace(' Win7','')
        $DriverName = ($DriverName).Replace(' Win10','')
        $DriverName = ($DriverName).Replace(' Win11','')
        $DriverName = ($DriverName).Replace(' Win 7','')
        $DriverName = ($DriverName).Replace(' Win 10','')
        $DriverName = ($DriverName).Replace(' Win 11','')
        $DriverName = ($DriverName).Replace(' Windows 7','')
        $DriverName = ($DriverName).Replace(' Windows 10','')
        $DriverName = ($DriverName).Replace(' Windows 11','')
        $DriverName = ($DriverName).Replace(' Driver Pack','')
        $DriverVersion = $item.Version.Trim()
        $DriverReleaseId = ($item.Url | Split-Path -Leaf).Replace('.exe','').ToUpper()
        $DriverGrouping = $null

        $DownloadFile = $item.Url | Split-Path -Leaf
        $SizeMB = ($item.Size.Trim() | Select-Object -Unique) / 1024
        $DriverUrl = $item.Url
        $DriverInfo = $item.CvaFileUrl
        $DriverDescription = $item.ReleaseNotesUrl
        $Hash = $item.MD5.Trim()

        if ($item.Name -match 'x64') {$OsArch = 'x64'}
        if ($item.Name -match 'x86') {$OsArch = 'x86'}
        if ($null -eq $OsArch) {$OsArch = 'x64'}
        if ($item.Name -match 'Win7') {$OsVersion = '6.1'}
        if ($item.Name -match 'Win 7') {$OsVersion = '6.1'}
        if ($item.Name -match 'Window 7') {$OsVersion = '6.1'}
        if ($item.Name -match 'Windows 7') {$OsVersion = '6.1'}
        if ($item.Name -match 'Win8') {$OsVersion = '6.3'}
        if ($item.Name -match 'Win 8') {$OsVersion = '6.3'}
        if ($item.Name -match 'Windows 8') {$OsVersion = '6.3'}
        if ($item.Name -match 'Win10') {$OsVersion = '10.0'}
        if ($item.Name -match 'Win 10') {$OsVersion = '10.0'}
        if ($item.Name -match 'Windows 10') {$OsVersion = '10.0'}
        if ($item.Name -match 'Win11') {$OsVersion = 'Win11'}
        if ($item.Name -match 'Win 11') {$OsVersion = 'Win11'}
        if ($item.Name -match 'Windows 11') {$OsVersion = 'Win11'}

        if ($item.Name -match 'G1') {$Generation = 'G1'}
        if ($item.Name -match 'G2') {$Generation = 'G2'}
        if ($item.Name -match 'G3') {$Generation = 'G3'}
        if ($item.Name -match 'G4') {$Generation = 'G4'}
        if ($item.Name -match 'G5') {$Generation = 'G5'}
        if ($item.Name -match 'G6') {$Generation = 'G6'}
        if ($item.Name -match 'G7') {$Generation = 'G7'}
        if ($item.Name -match 'G8') {$Generation = 'G8'}
        if ($item.Name -match 'G9') {$Generation = 'G8'}
        #=================================================
        # SystemFamily
        #=================================================
        #=================================================
        # Corrections
        #=================================================
        if ($SystemSku -contains '81C6') {$Generation = 'G4'}
        if ($SystemSku -contains '81C7') {$Generation = 'G4'}
        if ($SystemSku -contains '824C') {$Generation = 'G4'}
        #=================================================
        # Customizations
        #=================================================
        if (Test-Path "$DownloadPath\$DownloadFile") {
            $OSDStatus = 'Downloaded'
        }
        #=================================================
        # Create Object
        #=================================================
        $ObjectProperties = @{
            OSDVersion              = [string]$OSDVersion
            LastUpdate              = $(($LastUpdate).ToString("yyyy-MM-dd"))
            OSDStatus               = $OSDStatus
            OSDType                 = $OSDType
            OSDGroup                = $OSDGroup

            DriverName              = "$DriverName $OsVersion $OsArch $DriverVersion"
            DriverVersion           = $DriverVersion
            DriverReleaseId         = $DriverReleaseID

            OperatingSystem         = $OperatingSystem
            OsCode                  = $OsCode
            OsVersion               = $OsVersion
            OsArch                  = $OsArch
            OsBuildMax              = $OsBuildMax
            OsBuildMin              = $OsBuildMin

            Make                    = $Make
            MakeNe                  = $MakeNe
            MakeLike                = $MakeLike
            MakeNotLike             = $MakeNotLike
            MakeMatch               = $MakeMatch
            MakeNotMatch            = $MakeNotMatch

            Generation              = $Generation
            SystemFamily            = $SystemFamily

            Model                   = $Model
            ModelNe                 = $ModelNe
            ModelLike               = $ModelLike
            ModelNotLike            = $ModelNotLike
            ModelMatch              = $ModelMatch
            ModelNotMatch           = $ModelNotMatch

            SystemSku               = $SystemSku -split(',')
            SystemSkuNe             = $SystemSkuNe

            DriverGrouping          = "$Model $OsVersion $OsArch"
            DriverBundle            = $DriverBundle
            DriverWeight            = [int] $DriverWeight

            DownloadFile            = $DownloadFile
            SizeMB                  = [int] $SizeMB
            DriverUrl               = $DriverUrl
            DriverInfo              = $DriverInfo
            DriverDescription       = $DriverDescription
            Hash                    = $Hash
            OSDGuid                 = $OSDGuid
            IsSuperseded            = [bool] $IsSuperseded
        }
        New-Object -TypeName PSObject -Property $ObjectProperties
    }
    #=================================================
    # Supersedence
    #=================================================
    $global:GetOSDDriverHpModel = $global:GetOSDDriverHpModel | Sort-Object LastUpdate -Descending
    $CurrentOSDDriverHpModelPack = @()
    foreach ($HpModelPack in $global:GetOSDDriverHpModel) {
        if ($CurrentOSDDriverHpModelPack.DriverGrouping -match $HpModelPack.DriverGrouping) {
            $HpModelPack.IsSuperseded = $true
        } else { 
            $CurrentOSDDriverHpModelPack += $HpModelPack
        }
    }
    $global:GetOSDDriverHpModel = $global:GetOSDDriverHpModel | Where-Object {$_.IsSuperseded -eq $false}
    #=================================================
    # Select-Object
    #=================================================
    $global:GetOSDDriverHpModel = $global:GetOSDDriverHpModel | Select-Object LastUpdate,`
    OSDType, OSDGroup, OSDStatus, `
    DriverGrouping, DriverName, Make, Generation, Model, SystemSku,`
    DriverVersion, DriverReleaseId,`
    OsVersion, OsArch,`
    DownloadFile, SizeMB, DriverUrl, DriverInfo, DriverDescription,
    Hash, OSDGuid, OSDVersion
    #=================================================
    # Sort Object
    #=================================================
    $global:GetOSDDriverHpModel = $global:GetOSDDriverHpModel | Sort-Object LastUpdate -Descending
    #=================================================
    # Return
    #=================================================
    Return $global:GetOSDDriverHpModel
    #=================================================
}