Public/OSDCloud.DriverPack.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 |
function Get-OSDCloudDriverPack { <# .SYNOPSIS Gets the OSDCloud DriverPack for the current or specified computer model .DESCRIPTION Gets the OSDCloud DriverPack for the current or specified computer model .LINK https://github.com/OSDeploy/OSD/tree/master/Docs #> [CmdletBinding()] param ( [System.String] #Product is determined automatically by Get-MyComputerProduct $Product = (Get-MyComputerProduct), [System.String] [ValidateSet('Windows 11','Windows 10')] $OSVersion, [System.String] $OSReleaseID ) $ProductDriverPacks = Get-OSDCloudDriverPacks | Where-Object {($_.Product -contains $Product)} #================================================= # Results #================================================= if ($ProductDriverPacks) { if ($OSVersion) { $OSVersionDriverPacks = $ProductDriverPacks | Where-Object { $_.OS -match $OSVersion} if (-NOT $OSVersionDriverPacks) { $OSVersionDriverPacks = $ProductDriverPacks } } else { $OSVersionDriverPacks = $ProductDriverPacks } if ($OSReleaseID) { $OSReleaseIDDriverPacks = $OSVersionDriverPacks | Where-Object { $_.Name -match $OSReleaseID} if (-NOT $OSReleaseIDDriverPacks) { $OSReleaseIDDriverPacks = $OSVersionDriverPacks } } else { $OSReleaseIDDriverPacks = $OSVersionDriverPacks } $Results = $OSReleaseIDDriverPacks | Sort-Object -Property Name -Descending $Results[0] } else { Write-Verbose "Product $Product is not supported" } #================================================= } function Get-OSDCloudDriverPacks { <# .SYNOPSIS Returns the DriverPacks used by OSDCloud .DESCRIPTION Returns the DriverPacks used by OSDCloud .LINK https://github.com/OSDeploy/OSD/tree/master/Docs #> [CmdletBinding()] param () $Results = Get-Content -Path (Join-Path (Get-Module -Name OSD -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1).ModuleBase "Catalogs\CloudDriverPacks.json") | ConvertFrom-Json $Results } function Save-OSDCloudDriverPack { <# .SYNOPSIS` Gets the OSDCloud DriverPack for the current or specified computer model .DESCRIPTION Gets the OSDCloud DriverPack for the current or specified computer model .LINK https://github.com/OSDeploy/OSD/tree/master/Docs #> [CmdletBinding()] param ( [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [System.String[]] $Guid, [System.String] $DownloadPath = 'C:\Drivers', [System.Management.Automation.SwitchParameter] $Expand ) begin { #================================================= # Block #================================================= if ($Expand) { Block-StandardUser } Block-WindowsVersionNe10 #================================================= # Create Directory #================================================= if (-NOT (Test-Path "$DownloadPath")) { New-Item $DownloadPath -ItemType Directory -Force -ErrorAction Stop | Out-Null } $DriverPackList = Get-OSDCloudDriverPacks #================================================= } process { foreach($Item in $Guid) { $DriverPack = $DriverPackList | Where-Object { $_.Guid -eq $Item } if ($DriverPack) { $OutFile = Join-Path $DownloadPath $DriverPack.FileName Write-Verbose -Message "ReleaseDate: $($DriverPack.ReleaseDate)" Write-Verbose -Message "Name: $($DriverPack.Name)" Write-Verbose -Message "Product: $($DriverPack.Product)" Write-Verbose -Message "Url: $($DriverPack.Url)" if ($DriverPack.HashMD5) { Write-Verbose -Message "HashMD5: $($DriverPack.HashMD5)" } Write-Verbose -Message "OutFile: $OutFile" Save-WebFile -SourceUrl $DriverPack.Url -DestinationDirectory $DownloadPath -DestinationName $DriverPack.FileName if (! (Test-Path $OutFile)) { Write-Warning "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Driver Pack failed to download" } else { $GetItemOutFile = Get-Item $OutFile } $DriverPack | ConvertTo-Json | Out-File "$OutFile.json" -Encoding ascii -Width 2000 -Force } } } end {} } |