public/Update-OSDeployCoreDrivers.ps1
|
#Requires -PSEdition Core #Requires -Version 7.4 function Update-OSDeployCoreDrivers { <# .SYNOPSIS Refreshes the WinPE driver catalog and downloads the selected driver packages. .DESCRIPTION This is the supported public entrypoint for the OSDeployCore module. It refreshes the requested catalog sources, resolves the matching WinPE driver packages, and downloads and expands the selected packages to $env:ProgramData\OSDeployCore. All matching packages are processed automatically without prompting. .PARAMETER Name One or more source names to refresh and present for download. .PARAMETER Force Re-download driver packages even when a matching cached file already exists. .PARAMETER SkipWifiDrivers Exclude Wi-Fi driver packages (intel-wifi, microsoft-windows-wifi) from download and processing. ADK WinPE does not support wireless hardware, so Wi-Fi drivers are only needed when a WinRE-based boot image will be built. When no imported OS sources are present, this switch is enforced automatically. .PARAMETER DownloadOnly Download driver packages to the cache without expanding them. The downloaded file is saved to $env:ProgramData\OSDeployCore\cache\downloads\<vendor>\ but the expand step is skipped and no package.json metadata file is written. .EXAMPLE PS> Update-OSDeployCoreDrivers -Name 'dell' Refreshes the dell catalog and downloads all matching dell packages. .EXAMPLE PS> Update-OSDeployCoreDrivers -Name 'dell', 'hp' -WhatIf Shows the catalog refresh and download actions for dell and hp without executing them. .EXAMPLE PS> Update-OSDeployCoreDrivers Refreshes all configured sources and downloads all available packages. .EXAMPLE PS> Update-OSDeployCoreDrivers -Name 'dell' -WhatIf Refreshes the dell catalog and previews the download workflow without executing. .EXAMPLE PS> Update-OSDeployCoreDrivers -Name 'dell' -DownloadOnly Refreshes the dell catalog and downloads the .cab without expanding it. .EXAMPLE PS> Update-OSDeployCoreDrivers -SkipWifiDrivers Refreshes all configured sources, excludes Wi-Fi packages, and downloads all remaining packages. .OUTPUTS [System.IO.FileInfo] The downloaded file(s). .NOTES Author: David Segura Version: 0.1.0 Dependencies: Module Functions: Get-OSDeployCoreWinRESource, Initialize-OSDeployCorePaths, Save-CloudWinPEDriver, Test-IsAdministrator, Update-OSDeployCoreDriversCatalog, Write-OSDeployBanner, Write-OSDeployCoreDriversProgress Windows Features: Windows ADK WinPE Addon .NET Classes: [System.IO.FileInfo], [System.Management.Automation.CompletionResult] #> [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] [OutputType([System.IO.FileInfo])] param ( [Parameter(Position = 0)] [ArgumentCompleter({ param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $global:OSDeployModule.WinPEDrivers.PSObject.Properties | Where-Object { ($_.Value.UpdateUri -or $_.Value.DownloadUri) -and -not $_.Value.Disabled -and $_.Name -like "$wordToComplete*" } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Name) } })] [string[]]$Name, [Parameter()] [switch]$Force, [Parameter()] [switch]$SkipWifiDrivers, [Parameter()] [switch]$DownloadOnly, [Parameter()] [ValidateSet('amd64', 'arm64')] [System.String] $Architecture ) begin { Write-OSDeployBanner Write-Verbose "[$(Get-Date -format s)] [$($MyInvocation.MyCommand.Name)] Starting" Write-OSDeployCoreDriversProgress "Starting OSDeployCore Driver Update ..." # Requires Run as Administrator if (-not (Test-IsAdministrator)) { Write-Warning "[$($MyInvocation.MyCommand.Name)] This function must be Run as Administrator" return } Initialize-OSDeployCorePaths if (-not $SkipWifiDrivers) { $importedSources = Get-OSDeployCoreWinRESource -ErrorAction SilentlyContinue if (-not $importedSources) { $SkipWifiDrivers = $true Write-Warning "No imported OS sources found. Wi-Fi drivers require WinRE (ADK WinPE does not support wireless hardware) and will be skipped." } } } process { $targetLabel = if ($Name) { $Name -join ', ' } else { 'all refreshable sources' } $commonParameters = @{ Confirm = $false } if ($WhatIfPreference) { $commonParameters.WhatIf = $true } $catalogParameters = @{} if ($Name) { $catalogParameters.Name = $Name } if ($Force) { $catalogParameters.Force = $true } $saveParameters = @{ SkipCatalogRefresh = $true; Confirm = $false } if ($Name) { $saveParameters.Name = $Name } if ($Force) { $saveParameters.Force = $true } if ($SkipWifiDrivers) { $saveParameters.SkipWifiDrivers = $true } if ($DownloadOnly) { $saveParameters.DownloadOnly = $true } if ($Architecture) { $saveParameters.Architecture = $Architecture } if ($WhatIfPreference) { $saveParameters.WhatIf = $true } if ($WhatIfPreference) { Write-OSDeployCoreDriversProgress "WhatIf: Refreshing WinPE driver catalog for: $targetLabel" Update-OSDeployCoreDriversCatalog @catalogParameters @commonParameters | Out-Null Write-OSDeployCoreDriversProgress "WhatIf: Downloading and expanding WinPE driver packages ..." Save-CloudWinPEDriver @saveParameters return } if ($PSCmdlet.ShouldProcess($targetLabel, 'Refresh catalog and save WinPE drivers for BootMedia')) { Write-OSDeployCoreDriversProgress "Refreshing WinPE driver catalog for: $targetLabel" Update-OSDeployCoreDriversCatalog @catalogParameters @commonParameters | Out-Null Write-OSDeployCoreDriversProgress "Downloading and expanding WinPE driver packages ..." $driverResults = @(Save-CloudWinPEDriver @saveParameters) $downloadedCount = ($driverResults | Where-Object { $_ }).Count Write-OSDeployCoreDriversProgress "Complete. $downloadedCount driver package(s) processed." $driverResults } } end { Write-Verbose "[$(Get-Date -format s)] [$($MyInvocation.MyCommand.Name)] Complete" Write-OSDeployCoreDriversProgress "Update-OSDeployCoreDrivers complete" } } |