Private/Deploy/Expand-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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
function Expand-OSDDrivers {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
        [string]$PublishPath,

        [string]$ExpandDriverPath,

        [switch]$GridView,

        [string]$SetMake,
        [string]$SetModel,
        [string]$SetFamily,
        [string]$SetSku,

        [ValidateSet('x64','x86')]
        [string]$SetOSArch,

        [string]$SetOSBuild,

        #[ValidateSet('Client','Server')]
        #[string]$SetOSInstallationType,

        [ValidateSet('6.1','6.2','6.3','10.0')]
        [string]$SetOSVersion
    )
    #===================================================================================================
    # Get-OSDDriver
    #===================================================================================================
    $OSDDriverMultiPacks = @()
    $OSDDriverMultiPacks = Get-OSDDriverMultiPacks -PublishPath $PublishPath -ErrorAction SilentlyContinue

    $OSDDriverPackages = @()
    $OSDDriverPackages = Get-OSDDriverPackages -PublishPath $PublishPath -ErrorAction SilentlyContinue

    $OSDDriverTasks = @()
    $OSDDriverTasks = Get-OSDDriverTasks -PublishPath $PublishPath -ErrorAction SilentlyContinue
    #===================================================================================================
    # Connect to Task Sequence Environment
    #===================================================================================================
    try {
        $TSEnv = New-Object -ComObject Microsoft.SMS.TSEnvironment
    }
    catch [System.Exception] {
        Write-Warning -Message "Unable to construct Microsoft.SMS.TSEnvironment object"
    }
    #===================================================================================================
    # Defaults
    #===================================================================================================
    $IsWinPE = $env:SystemDrive -eq 'X:'
    Write-Verbose "IsWinPE: $IsWinPE" -Verbose
    #===================================================================================================
    # Set OSDisk
    #===================================================================================================
    $OSDisk = 'C:'
    #===================================================================================================
    # WinPE = Find OSDisk
    #===================================================================================================
    if ($IsWinPE) {
        if ($TSEnv) {
            #MDT Default
            if ($TSEnv.Value('OSDisk') -match ':') {$OSDisk = $TSEnv.Value('OSDisk')}
            #MDT Secondary
            elseif ($TSEnv.Value('OSDTargetDriveCache') -match ':') {$OSDisk = $TSEnv.Value('OSDTargetDriveCache')}
            #SCCM Default
            elseif ($TSEnv.Value('OSDTargetSystemDrive') -match ':') {$OSDisk = $TSEnv.Value('OSDTargetSystemDrive')}
        }
    } else {
        $OSDisk = $env:SystemDrive
    }
    Write-Verbose "OSDisk: $OSDisk" -Verbose
    #===================================================================================================
    # ExpandDriverPath
    #===================================================================================================
    if (!$ExpandDriverPath) {$ExpandDriverPath = $OSDisk + '\Drivers'}
    Write-Verbose "ExpandDriverPath: $ExpandDriverPath" -Verbose
    #===================================================================================================
    # Validate
    #===================================================================================================
    if (-not (Test-Path "$ExpandDriverPath")) {
        try {
            New-Item -Path "$ExpandDriverPath\" -ItemType Directory -Force | Out-Null
        }
        catch {
            Write-Warning "Could not create $ExpandDriverPath ... Exiting"
            Start-Sleep 10
            Exit 0
        }
    }
    #===================================================================================================
    # Start-Transcript
    #===================================================================================================
    $LogName = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-OSDDrivers.log"
    Start-Transcript -Path "$ExpandDriverPath\$LogName" | Out-Null
    #===================================================================================================
    # Image OSArchitecture
    #===================================================================================================
    if ($SetOSArch) {
        Write-Verbose "SetOSArch (Parameter): $SetOSArch" -Verbose
        $ImageOSArchitecture = $SetOSArch
    } else {
        #MDT
        if ($TSEnv) {$ImageProcessor = $TSEnv.Value('ImageProcessor')}

        if ($ImageProcessor) {
            Write-Verbose "ImageProcessor (TSEnv): $ImageProcessor" -Verbose
            $ImageOSArchitecture = $ImageProcessor
        } else {
            $CimOSArchitecture = (Get-CimInstance -ClassName Win32_OperatingSystem).OSArchitecture
            Write-Verbose "Cim OS Architecture (Win32_OperatingSystem): $CimOSArchitecture" -Verbose
            if ($CimOSArchitecture -like "*64*") {$ImageOSArchitecture = 'x64'}
            if ($CimOSArchitecture -like "*32*") {$ImageOSArchitecture = 'x86'}

            if ($TSEnv) {
                #Write-Warning "This parameter can be set by adding a Task Sequence Variable: g"
            }
        }
    }
    Write-Verbose "Image OSArchitecture: $ImageOSArchitecture" -Verbose
    #===================================================================================================
    # ImageOSBuild
    #===================================================================================================
    if ($SetOSBuild) {
        Write-Verbose "SetOSBuild (Parameter): $SetOSBuild" -Verbose
        $ImageOSBuild = $SetOSBuild
    } else {
        #MDT
        if ($TSEnv) {$ImageBuild = $TSEnv.Value('ImageBuild')}

        if ($ImageBuild) {
            Write-Verbose "ImageBuild (TSEnv): $ImageBuild" -Verbose
            $ImageOSBuild = ([version]$ImageBuild).Build
        } else {
            $ImageOSBuild = (Get-CimInstance -ClassName Win32_OperatingSystem).BuildNumber
            Write-Verbose "Cim OS BuildNumber (Win32_OperatingSystem): $ImageOSBuild" -Verbose
        }
    }
    Write-Verbose "Image OSBuild: $ImageOSBuild" -Verbose
    #===================================================================================================
    # ImageOSVersion
    #===================================================================================================
    if ($SetOSVersion) {
        Write-Verbose "SetOSVersion (Parameter): $SetOSVersion" -Verbose
        $ImageOSVersion = $SetOSVersion
    } else {
        #MDT
        if ($TSEnv) {$ImageBuild = $TSEnv.Value('ImageBuild')}

        if ($ImageBuild) {
            Write-Verbose "ImageBuild (TSEnv): $ImageBuild" -Verbose
            $ImageOSVersion = "$(([version]$ImageBuild).Major).$(([version]$ImageBuild).Minor)"
        } else {
            $CimOSVersion = (Get-CimInstance -ClassName Win32_OperatingSystem).Version
            Write-Verbose "Cim OS Version (Win32_OperatingSystem): $CimOSVersion" -Verbose
            $ImageOSVersion = "$(([version]$CimOSVersion).Major).$(([version]$CimOSVersion).Minor)"
        }
    }
    Write-Verbose "Image OSVersion: $ImageOSVersion" -Verbose

    #TODO
    #===================================================================================================
    # ImageOSInstallationType
    #===================================================================================================
<# if ($TSEnv) {$TaskSequenceTemplate = $TSEnv.Value('TaskSequenceTemplate')}
 
    if ($SetOSInstallationType) {
        Write-Verbose "Reading value from Parameter" -Verbose
        $ImageOSInstallationType = $SetOSInstallationType
    } elseif ($TaskSequenceTemplate) {
        Write-Verbose "Reading value from TSEnv" -Verbose
        if ($TaskSequenceTemplate -like "*Client*") {$ImageOSInstallationType = 'Client'}
        if ($TaskSequenceTemplate -like "*Server*") {$ImageOSInstallationType = 'Server'}
    } else {
        Write-Verbose "Reading value from Registry" -Verbose
        $ImageOSInstallationType = (Get-ItemProperty 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion').InstallationType
    }
    if ($ImageOSInstallationType -eq 'WinPE') {$ImageOSInstallationType = 'Client'}
    Write-Verbose "Image OSInstallationType: $ImageOSInstallationType" -Verbose #>

    #===================================================================================================
    # Hardware
    #===================================================================================================
    $SystemMake = (Get-CimInstance -ClassName Win32_ComputerSystem).Manufacturer
    if ($SetMake) {$SystemMake = $SetMake}
    Write-Verbose "System Make: $SystemMake" -Verbose

    $SystemModel = (Get-CimInstance -ClassName Win32_ComputerSystem).Model
    if ($SetModel) {$SystemModel = $SetModel}
    Write-Verbose "System Model: $SystemModel" -Verbose

    $SystemFamily = (Get-CimInstance -ClassName Win32_ComputerSystem).SystemFamily
    if ($SetFamily) {$SystemFamily = $SetFamily}
    Write-Verbose "System Family: $SystemFamily" -Verbose

    $SystemSKUNumber = (Get-CimInstance -ClassName Win32_ComputerSystem).SystemSKUNumber
    if ($SetSku) {$SystemSKUNumber = $SetSku}
    Write-Verbose "System SKUNumber: $SystemSKUNumber" -Verbose
    #===================================================================================================
    # Save-MyHardware
    #===================================================================================================
    $MyHardware = @()
    Save-MyHardware -ExpandDriverPath $ExpandDriverPath | Out-Null
    $MyHardware = Get-MyHardware | Select-Object -Property DeviceID, Caption
    # Alternate Method
    # $MyHardware = (Save-MyHardware -ExpandDriverPath $ExpandDriverPath | Import-CliXml | Select-Object -Property DeviceID, Caption)

    #===================================================================================================
    # Process MultiPacks
    #===================================================================================================
    Write-Host "Searching OSDDriver Tasks ..." -ForegroundColor Green
    $ExpandDrivers = @()

    $DriverPacks = @()
    $MultiPacks = @()
    $NvidiaPacks = @()
    #===================================================================================================
    # DriverTaskFile
    #===================================================================================================
    foreach ($DriverTaskFile in $OSDDriverTasks) {
        #===================================================================================================
        # Set Defaults
        #===================================================================================================
        $ExpandDriverPackage = $true
        #===================================================================================================
        # Variables
        #===================================================================================================
        $DriverTaskBaseName     = $DriverTaskFile.BaseName
        $DriverTaskDirectory    = $DriverTaskFile.DirectoryName
        $DriverTaskFullName     = $DriverTaskFile.FullName
        
        $DriverTaskGroup         = Split-Path $DriverTaskDirectory -Leaf

        $DriverTaskCab          = "$(Join-Path $DriverTaskDirectory $DriverTaskBaseName).cab"
        $DriverTaskMultiPack      = "$(Join-Path $DriverTaskDirectory $DriverTaskBaseName).multipack"

        Write-Verbose "DriverTaskGroup: $DriverTaskGroup"
        Write-Verbose "DriverTaskBaseName: $DriverTaskBaseName"
        Write-Verbose "DriverTaskDirectory: $DriverTaskDirectory"
        Write-Verbose "DriverTaskFullName: $DriverTaskFullName"
        Write-Verbose "DriverTaskCab: $DriverTaskCab"
        Write-Verbose "DriverTaskMultiPack: $DriverTaskMultiPack"
        #===================================================================================================
        # DriverTask
        #===================================================================================================
        $DriverTask = @()
        $DriverTask = Get-Content "$DriverTaskFullName" | ConvertFrom-Json
        #Write-Host -ForegroundColor Gray "$DriverTaskFullName"
        #===================================================================================================
        # OsVersion
        #===================================================================================================
        if ($DriverTask.OsVersion) {
            $ExpandDriverPackage = $false
            foreach ($item in $DriverTask.OsVersion) {
                Write-Verbose "Driver Package Compatible OsArch: $item"
                if ($ImageOSVersion -match $item) {$ExpandDriverPackage = $true}
            }
            if ($ExpandDriverPackage -eq $false) {
                Write-Verbose "OSDDriver is not compatible with ImageOSVersion $ImageOSVersion"
                Continue
            }
        }
        #===================================================================================================
        # OsArch
        #===================================================================================================
        if ($DriverTask.OsArch) {
            $ExpandDriverPackage = $false
            foreach ($item in $DriverTask.OsArch) {
                Write-Verbose "Driver Package Compatible OsArch: $item"
                if ($ImageOSArchitecture -match $item) {$ExpandDriverPackage = $true}
            }
            if ($ExpandDriverPackage -eq $false) {
                Write-Verbose "OSDDriver is not compatible with ImageOSArchitecture $ImageOSArchitecture"
                Continue
            }
        }
        #===================================================================================================
        # Make
        #===================================================================================================
        if ($DriverTask.Make) {
            $ExpandDriverPackage = $false
            foreach ($item in $DriverTask.Make) {
                Write-Verbose "Driver CAB Compatible Make: $item"
                if ($SystemMake -match $item) {$ExpandDriverPackage = $true}
            }
            if ($ExpandDriverPackage -eq $false) {
                Write-Verbose "OSDDriver is not compatible with SystemMake $SystemMake"
                Continue
            }
        }
        #===================================================================================================
        # ModelPack DellModel
        #===================================================================================================
        if ($DriverTask.OSDType -eq 'ModelPack' -and $DriverTask.OSDGroup -eq 'DellModel') {
            if ($DriverTask.Model -or $DriverTask.SystemSku) {
                $ExpandDriverPackage = $false
                foreach ($item in $DriverTask.Model) {
                    if ($SystemModel -eq $item) {
                        $ExpandDriverPackage = $true
                        Write-Verbose "OSDDriver is compatible with $SystemModel"
                        #$ExpandDrivers += $DriverPackage
                        Continue
                    }
                }
                foreach ($item in $DriverTask.SystemSku) {
                    if ($SystemSKUNumber -eq $item) {
                        $ExpandDriverPackage = $true
                        Write-Verbose "OSDDriver is compatible with SystemSKUNumber $SystemSKUNumber"
                        #$ExpandDrivers += $DriverPackage
                        Continue
                    }
                }
                if ($ExpandDriverPackage -eq $false) {
                    Write-Verbose "OSDDriver is not compatible with SystemModel $SystemModel $SystemSKUNumber"
                    Continue
                } else {
                    Write-Verbose "OSDDriver $DriverTaskBaseName is compatible with $SystemModel"
                    #$ExpandDrivers += $DriverPackage
                    #Continue
                }
            }
        }
        #===================================================================================================
        # MakeNotMatch
        #===================================================================================================
        if ($DriverTask.MakeNotMatch) {
            foreach ($item in $DriverTask.MakeNotMatch) {
                if ($SystemMake -match $item) {$ExpandDriverPackage = $false}
            }
            if ($ExpandDriverPackage -eq $false) {Continue}
        }
        #===================================================================================================
        # ModelNotMatch
        #===================================================================================================
        if ($DriverTask.ModelNotMatch) {
            foreach ($item in $DriverTask.ModelNotMatch) {
                if ($SystemModel -match $item) {$ExpandDriverPackage = $false}
            }
            if ($ExpandDriverPackage -eq $false) {Continue}
        }
        #===================================================================================================
        # OsBuildMin
        #===================================================================================================
<# if ($DriverTask.OsBuildMin) {
            $OsBuildMin = $DriverTask.OsBuildMin
            if (-not($ImageOSBuild -ge "$($OsBuildMin)")) {
                Write-Host "Image OSBuild $ImageOSBuild is not Greater or Equal to OSBuild Minimum $($OsBuildMin)" -ForegroundColor DarkGray
                Continue
            }
        } #>

        #===================================================================================================
        # OsBuildMax
        #===================================================================================================
<# if ($DriverTask.OsBuildMax) {
            $OsBuildMax = $DriverTask.OsBuildMax
            if (-not($ImageOSBuild -le "$($OsBuildMax)")) {
                Write-Host "$DriverPackageFullName reuires an Image OSBuild $ImageOSBuild is not Less or Equal to required OSBuild Maximum $($OsBuildMax)" -ForegroundColor DarkGray
                Continue
            }
        } #>

        #===================================================================================================
        # Separate Tasks
        #===================================================================================================
        if (Test-Path "$DriverTaskMultiPack") {
            $MultiPacks += $DriverTaskFile
            Continue
        }
        if ($DriverTask.OSDGroup -eq 'NvidiaPack') {
            $NvidiaPacks += $DriverTaskFile
            Continue
        }
        $DriverPacks += $DriverTaskFile
        Continue
    }
    #===================================================================================================
    # Process DriverPacks
    #===================================================================================================
    if ($DriverPacks) {
        Write-Host "Processing DriverPacks ..." -ForegroundColor Green
        $ExpandDriverPacks = @()
        foreach ($DriverTaskFile in $DriverPacks) {
    
            $DriverTaskBaseName     = $DriverTaskFile.BaseName
            $DriverTaskDirectory    = $DriverTaskFile.DirectoryName
            $DriverTaskFullName     = $DriverTaskFile.FullName
            
            $DriverTaskGroup         = Split-Path $DriverTaskDirectory -Leaf
    
            $DriverTaskCab          = "$(Join-Path $DriverTaskDirectory $DriverTaskBaseName).cab"
            $DriverTaskZip          = "$(Join-Path $DriverTaskDirectory $DriverTaskBaseName).zip"
            $DriverTaskPnp          = "$(Join-Path $DriverTaskDirectory $DriverTaskBaseName).drvpnp"
            $DriverTaskMultiPack      = "$(Join-Path $DriverTaskDirectory $DriverTaskBaseName).multipack"
    
    
            Write-Verbose "DriverTaskGroup: $DriverTaskGroup"
            Write-Verbose "DriverTaskBaseName: $DriverTaskBaseName"
            Write-Verbose "DriverTaskDirectory: $DriverTaskDirectory"
            Write-Verbose "DriverTaskFullName: $DriverTaskFullName"
            Write-Verbose "DriverTaskCab: $DriverTaskCab"
            Write-Verbose "DriverTaskPnp: $DriverTaskPnp"
            Write-Verbose "DriverTaskMultiPack: $DriverTaskMultiPack"
    
            Write-Host -ForegroundColor Gray "$($DriverTaskFile.FullName)"
    
            if (Test-Path $DriverTaskPnp) {
                $ExpandDriverPackage = $false
                $HardwareIdMatches = @()
                $OSDPnpFile = @()
                $OSDPnpFile = Import-CliXml -Path "$DriverTaskPnp"
            
                foreach ($PnpDriverId in $OSDPnpFile) {
                    $HardwareDescription = $($PnpDriverId.HardwareDescription)
                    $HardwareId = $($PnpDriverId.HardwareId)
            
                    if ($MyHardware -like "*$HardwareId*") {
                        #Write-Host "$HardwareDescription $HardwareId " -Foregroundcolor Cyan
                        $ExpandDriverPackage = $true
                        $HardwareIdMatches += "$HardwareDescription $HardwareId"
                    }
                }
    
                if ($ExpandDriverPackage -eq $false) {
                    Write-Verbose "Driver does not support the Hardware in this system"
                    Continue
                }
                if ($HardwareIdMatches) {
                    #Write-Host "HardwareID Match"
                    foreach ($HardwareIdMatch in $HardwareIdMatches) {
                        Write-Verbose "$($HardwareIdMatch)" -Verbose
                    }
                }
            }
            if (Test-Path $DriverTaskCab) {
                $ExpandDriverPacks += $DriverTaskCab
            }
            if (Test-Path $DriverTaskZip) {
                $ExpandDriverPacks += $DriverTaskZip
            }
        }
    }
    #===================================================================================================
    # Process NvidiaPacks
    #===================================================================================================
    if ($NvidiaPacks) {
        Write-Host "Processing NvidiaPacks ..." -ForegroundColor Green
        $ExpandNvidiaPacks = @()
        $ExpandNvidiaTasks = @()
        foreach ($DriverTaskFile in $NvidiaPacks) {
            $DriverTaskBaseName     = $DriverTaskFile.BaseName
            $DriverTaskDirectory    = $DriverTaskFile.DirectoryName
            $DriverTaskFullName     = $DriverTaskFile.FullName
            
            $DriverTaskGroup         = Split-Path $DriverTaskDirectory -Leaf
    
            $DriverTaskCab          = "$(Join-Path $DriverTaskDirectory $DriverTaskBaseName).cab"
            $DriverTaskZip          = "$(Join-Path $DriverTaskDirectory $DriverTaskBaseName).zip"
            $DriverTaskPnp          = "$(Join-Path $DriverTaskDirectory $DriverTaskBaseName).drvpnp"
            $DriverTaskMultiPack      = "$(Join-Path $DriverTaskDirectory $DriverTaskBaseName).multipack"
    
    
            Write-Verbose "DriverTaskGroup: $DriverTaskGroup"
            Write-Verbose "DriverTaskBaseName: $DriverTaskBaseName"
            Write-Verbose "DriverTaskDirectory: $DriverTaskDirectory"
            Write-Verbose "DriverTaskFullName: $DriverTaskFullName"
            Write-Verbose "DriverTaskCab: $DriverTaskCab"
            Write-Verbose "DriverTaskPnp: $DriverTaskPnp"
            Write-Verbose "DriverTaskMultiPack: $DriverTaskMultiPack"
    
            Write-Host -ForegroundColor Gray "$($DriverTaskFile.FullName)"
    
            if (Test-Path $DriverTaskPnp) {
                $ExpandDriverPackage = $false
                $HardwareIdMatches = @()
                $OSDPnpFile = @()
                $OSDPnpFile = Import-CliXml -Path "$DriverTaskPnp"
            
                foreach ($PnpDriverId in $OSDPnpFile) {
                    $HardwareDescription = $($PnpDriverId.HardwareDescription)
                    $HardwareId = $($PnpDriverId.HardwareId)
            
                    if ($MyHardware -like "*$HardwareId*") {
                        #Write-Host "$HardwareDescription $HardwareId " -Foregroundcolor Cyan
                        $ExpandDriverPackage = $true
                        $HardwareIdMatches += "$HardwareDescription $HardwareId"
                    }
                }
    
                if ($ExpandDriverPackage -eq $false) {
                    Write-Verbose "Driver does not support the Hardware in this system"
                    Continue
                }
                if ($HardwareIdMatches) {
                    #Write-Host "HardwareID Match"
                    foreach ($HardwareIdMatch in $HardwareIdMatches) {
                        Write-Verbose "$($HardwareIdMatch)" -Verbose
                    }
                }
            }
            if (Test-Path $DriverTaskCab) {
                $ExpandNvidiaTasks += $DriverTaskFullName
                $ExpandNvidiaPacks += $DriverTaskCab
                Continue
            }
            if (Test-Path $DriverTaskZip) {
                $ExpandNvidiaTasks += $DriverTaskFullName
                $ExpandNvidiaPacks += $DriverTaskZip
                Continue
            }
            $ExpandNvidiaTasks += $DriverTaskFullName
        }
    }
    #===================================================================================================
    # Throw NvidiaPacks
    #===================================================================================================
    if ($ExpandNvidiaTasks) {
        $ExpandNvidiaTasks = $ExpandNvidiaTasks | Sort-Object | Select-Object -Last 1

        $NvidiaTask = @()
        $NvidiaTask = Get-Content "$ExpandNvidiaTasks" | ConvertFrom-Json
        Write-Verbose "Selecting NvidiaPack Grouping $($NvidiaTask.DriverGrouping)" -Verbose
        Write-Verbose "Selecting NvidiaPack ReleaseId $($NvidiaTask.DriverReleaseId)" -Verbose

        if ($TSEnv) {
            Write-Verbose "Setting Task Sequence Variable NvidiaPackGrouping to $($NvidiaTask.DriverGrouping)" -Verbose
            $TSEnv.Value('NvidiaPackGrouping') = "$($NvidiaTask.DriverGrouping)"
            Write-Verbose "Setting Task Sequence Variable NvidiaPack to $($NvidiaTask.DriverReleaseId)" -Verbose
            $TSEnv.Value('NvidiaPack') = "$($NvidiaTask.DriverReleaseId)"
        }
        $ExpandNvidiaPacks = $ExpandNvidiaPacks | Where-Object {$_ -match $NvidiaTask.DriverReleaseId}
    }
    #===================================================================================================
    # Expand DriverPacks
    #===================================================================================================
    if ($ExpandDriverPacks) {
        Write-Host "Expanding DriverPacks ..." -Foregroundcolor Green
        foreach ($ExpandDriverPack in $ExpandDriverPacks) {
            $ExpandItem = Get-Item $ExpandDriverPack | Select-Object -Property *

            $DriverPackageName = $ExpandItem.Name
            $DriverPackageBaseName = $ExpandItem.BaseName
            $DriverPackageFullName = $ExpandItem.FullName
            $DriverPackageDirectoryName = $ExpandItem.DirectoryName

            Write-Verbose "DriverPackageName: $DriverPackageName"
            Write-Verbose "DriverPackageBaseName: $DriverPackageBaseName"
            Write-Verbose "DriverPackageFullName: $DriverPackageFullName"
            Write-Verbose "DriverPackageDirectoryName: $DriverPackageDirectoryName"

            if (!(Test-Path "$ExpandDriverPath\$DriverPackageBaseName")) {
                New-Item -Path "$ExpandDriverPath\$DriverPackageBaseName" -ItemType Directory -Force | Out-Null
            }
            if ($DriverPackageName -match '.cab') {
                #Write-Host "Expanding CAB $DriverPackageFullName to $ExpandDriverPath\$DriverPackageBaseName" -ForegroundColor Cyan
                Write-Verbose "Expanding $ExpandDriverPath\$DriverPackageBaseName" -Verbose
                Expand -R "$DriverPackageFullName" -F:* "$ExpandDriverPath\$DriverPackageBaseName" | Out-Null
            }
            if ($DriverPackageName -match '.zip') {
                Write-Host "Expanding ZIP $DriverPackageFullName to $ExpandDriverPath\$DriverPackageBaseName" -ForegroundColor Cyan
                Expand-Archive -Path "$DriverPackageFullName" -DestinationPath "$ExpandDriverPath" -Force
            }
        }
    }
    #===================================================================================================
    # Expand NvidiaPacks
    #===================================================================================================
    if ($ExpandNvidiaPacks) {
        Write-Host "Expanding NvidiaPacks ..." -Foregroundcolor Green
        foreach ($ExpandDriverPack in $ExpandNvidiaPacks) {
            $ExpandItem = Get-Item $ExpandDriverPack | Select-Object -Property *

            $DriverPackageName = $ExpandItem.Name
            $DriverPackageBaseName = $ExpandItem.BaseName
            $DriverPackageFullName = $ExpandItem.FullName
            $DriverPackageDirectoryName = $ExpandItem.DirectoryName

            Write-Verbose "DriverPackageName: $DriverPackageName"
            Write-Verbose "DriverPackageBaseName: $DriverPackageBaseName"
            Write-Verbose "DriverPackageFullName: $DriverPackageFullName"
            Write-Verbose "DriverPackageDirectoryName: $DriverPackageDirectoryName"

            if (!(Test-Path "$ExpandDriverPath\$DriverPackageBaseName")) {
                New-Item -Path "$ExpandDriverPath\$DriverPackageBaseName" -ItemType Directory -Force | Out-Null
            }
            if ($DriverPackageName -match '.cab') {
                #Write-Host "Expanding CAB $DriverPackageFullName to $ExpandDriverPath\$DriverPackageBaseName" -ForegroundColor Cyan
                Write-Verbose "Expanding $ExpandDriverPath\$DriverPackageBaseName" -Verbose
                Expand -R "$DriverPackageFullName" -F:* "$ExpandDriverPath\$DriverPackageBaseName" | Out-Null
            }
            if ($DriverPackageName -match '.zip') {
                Write-Host "Expanding ZIP $DriverPackageFullName to $ExpandDriverPath\$DriverPackageBaseName" -ForegroundColor Cyan
                Expand-Archive -Path "$DriverPackageFullName" -DestinationPath "$ExpandDriverPath" -Force
            }
        }
    }
    #===================================================================================================
    # Process MultiPacks
    #===================================================================================================
    if ($MultiPacks) {
        Write-Host "Processing MultiPacks ..." -ForegroundColor Green
        foreach ($DriverTaskFile in $MultiPacks) {
            $DriverTaskBaseName     = $DriverTaskFile.BaseName
            $DriverTaskDirectory    = $DriverTaskFile.DirectoryName
            $DriverTaskFullName     = $DriverTaskFile.FullName
            
            $DriverTaskGroup         = Split-Path $DriverTaskDirectory -Leaf
            $DriverTaskMultiPack      = "$(Join-Path $DriverTaskDirectory $DriverTaskBaseName).multipack"
    
    
            Write-Verbose "DriverTaskGroup: $DriverTaskGroup"
            Write-Verbose "DriverTaskBaseName: $DriverTaskBaseName"
            Write-Verbose "DriverTaskDirectory: $DriverTaskDirectory"
            Write-Verbose "DriverTaskFullName: $DriverTaskFullName"
            Write-Verbose "DriverTaskMultiPack: $DriverTaskMultiPack"
    
            Write-Host -ForegroundColor Gray "$($DriverTaskFile.FullName)"
    
            if (!(Test-Path "$DriverTaskMultiPack")) {
                Write-Verbose "Could not find $DriverTaskMultiPack"
                Continue
            }
    
            #===================================================================================================
            # MultiPackFileList
            #===================================================================================================
            $MultiPackDrivers = @()
            $MultiPackDrivers = Get-Content "$DriverTaskMultiPack" | ConvertFrom-Json
            foreach ($ExpandDriver in $MultiPackDrivers) {
                $MultiPackDriverFullName = (Join-Path $DriverTaskDirectory $ExpandDriver)
                Write-Verbose "MultiPackDriverFullName: $MultiPackDriverFullName"
    
                if (Test-Path "$MultiPackDriverFullName") {
                    $ExpandMultiPack = (Join-Path $ExpandDriverPath $DriverTaskBaseName)
                    Write-Verbose "ExpandMultiPack: $ExpandMultiPack"
                    
                    $MultiPackDriverBaseName = ((Get-Item $MultiPackDriverFullName).BaseName)
                    Write-Verbose "MultiPackDriverBaseName: $MultiPackDriverBaseName"
                    $MultiPackDriverCategory = ((Get-Item $MultiPackDriverFullName).Directory.Name)
                    Write-Verbose "MultiPackDriverCategory: $MultiPackDriverCategory"
                    $MultiPackDriverOsArch = ((Get-Item $MultiPackDriverFullName).Directory.Parent)
                    Write-Verbose "MultiPackDriverOsArch: $MultiPackDriverOsArch"
    
                    $ExpandParent = "$ExpandMultiPack\$MultiPackDriverOsArch\$MultiPackDriverCategory"
                    $ExpandDirectory = "$ExpandParent\$MultiPackDriverBaseName"
    
                    Write-Verbose "Expanding $ExpandDirectory" -Verbose
    
                    if (!(Test-Path "$ExpandDirectory")) {
                        New-Item -Path "$ExpandDirectory" -ItemType Directory -Force | Out-Null
                    }
                    if ($MultiPackDriverFullName -match '.cab') {
                        Write-Verbose "Expanding CAB $MultiPackDriverFullName to $ExpandDirectory"
                        Expand -R "$MultiPackDriverFullName" -F:* "$ExpandDirectory" | Out-Null
                    }
                    if ($MultiPackDriverFullName -match '.zip') {
                        Write-Verbose "Expanding ZIP $MultiPackDriverFullName to $ExpandDirectory"
                        Expand-Archive -Path "$MultiPackDriverFullName" -DestinationPath "$ExpandParent" -Force
                    }
                }
            }
        }
    }
<# #===================================================================================================
    # Process MultiPacks
    #===================================================================================================
    Write-Host "Searching OSDDriver MultiPacks ..." -ForegroundColor Green
    $ExpandDrivers = @()
 
    foreach ($MultiPack in $OSDDriverMultiPacks) {
        #===================================================================================================
        # MultiPackFileList
        #===================================================================================================
        $MultiPackDrivers = @()
        $MultiPackDrivers = Get-Content "$MultiPackFileList" | ConvertFrom-Json
        $MultiPackDrivers = $MultiPackDrivers | Where-Object {$_ -match $ImageOSArchitecture}
 
        foreach ($ExpandDriver in $MultiPackDrivers) {
 
            $MultiPackDriverFullName = (Join-Path $MultiPackDirectory $ExpandDriver)
            Write-Verbose "$MultiPackDriverFullName"
 
            if (Test-Path "$MultiPackDriverFullName") {
                $ExpandMultiPack = (Join-Path $ExpandDriverPath $MultiPackName)
                Write-Verbose "$ExpandMultiPack"
                 
                $MultiPackDriverBaseName = ((Get-Item $MultiPackDriverFullName).BaseName)
                Write-Verbose "$MultiPackDriverBaseName"
                $MultiPackDriverCategory = ((Get-Item $MultiPackDriverFullName).Directory.Name)
                Write-Verbose "$MultiPackDriverCategory"
                $MultiPackDriverOsArch = ((Get-Item $MultiPackDriverFullName).Directory.Parent)
                Write-Verbose "$MultiPackDriverOsArch"
 
                $ExpandParent = "$ExpandMultiPack\$MultiPackDriverOsArch\$MultiPackDriverCategory"
                $ExpandDirectory = "$ExpandParent\$MultiPackDriverBaseName"
 
                Write-Verbose "Expanding $ExpandDirectory" -Verbose
 
                if (!(Test-Path "$ExpandDirectory")) {
                    New-Item -Path "$ExpandDirectory" -ItemType Directory -Force | Out-Null
                }
                if ($MultiPackDriverFullName -match '.cab') {
                    Write-Verbose "Expanding CAB $MultiPackDriverFullName to $ExpandDirectory"
                    Expand -R "$MultiPackDriverFullName" -F:* "$ExpandDirectory" | Out-Null
                }
                if ($MultiPackDriverFullName -match '.zip') {
                    Write-Verbose "Expanding ZIP $MultiPackDriverFullName to $ExpandDirectory"
                    Expand-Archive -Path "$MultiPackDriverFullName" -DestinationPath "$ExpandParent" -Force
                }
            }
        }
    } #>

    Stop-Transcript | Out-Null
}