Two fixes

- Fixed an issue with UWP apps downloaded via Winget weren't being fully installed. Added /StubPackageOption:installfull to the dism command
- Fixed an issue with Surface Drivers not downloading
This commit is contained in:
rbalsleyMSFT
2024-09-17 13:50:16 -07:00
parent 60d147c71d
commit 378941cd5c
2 changed files with 192 additions and 22 deletions
@@ -30,11 +30,8 @@ for /d %%D in ("%basepath%\*") do (
) )
) )
) )
@REM for %%F in ("!appfolder!\*.xml") do (
@REM set "licensefile=%%F"
@REM )
if defined mainpackage ( if defined mainpackage (
set "dism_command=DISM /Online /Add-ProvisionedAppxPackage /PackagePath:"!mainpackage!"" set "dism_command=DISM /Online /Add-ProvisionedAppxPackage /PackagePath:"!mainpackage!" /Region:all /StubPackageOption:installfull"
if exist "!dependenciesfolder!" ( if exist "!dependenciesfolder!" (
for %%G in ("!dependenciesfolder!\*") do ( for %%G in ("!dependenciesfolder!\*") do (
set "dism_command=!dism_command! /DependencyPackagePath:"%%G"" set "dism_command=!dism_command! /DependencyPackagePath:"%%G""
@@ -48,7 +45,6 @@ for /d %%D in ("%basepath%\*") do (
) else ( ) else (
set "dism_command=!dism_command! /SkipLicense" set "dism_command=!dism_command! /SkipLicense"
) )
set "dism_command=!dism_command! /Region:All"
echo !dism_command! echo !dism_command!
!dism_command! !dism_command!
) )
+191 -17
View File
@@ -336,7 +336,7 @@ param(
[bool]$AllowExternalHardDiskMedia, [bool]$AllowExternalHardDiskMedia,
[bool]$PromptExternalHardDiskMedia = $true [bool]$PromptExternalHardDiskMedia = $true
) )
$version = '2409.1' $version = '2409.2'
#Check if Hyper-V feature is installed (requires only checks the module) #Check if Hyper-V feature is installed (requires only checks the module)
$osInfo = Get-WmiObject -Class Win32_OperatingSystem $osInfo = Get-WmiObject -Class Win32_OperatingSystem
@@ -541,6 +541,163 @@ function Start-BitsTransferWithRetry {
return $false return $false
} }
# function Get-MicrosoftDrivers {
# param (
# [string]$Make,
# [string]$Model,
# [int]$WindowsRelease
# )
# $url = "https://support.microsoft.com/en-us/surface/download-drivers-and-firmware-for-surface-09bb2e09-2a4b-cb69-0951-078a7739e120"
# # Download the webpage content
# WriteLog "Getting Surface driver information from $url"
# $OriginalVerbosePreference = $VerbosePreference
# $VerbosePreference = 'SilentlyContinue'
# $webContent = Invoke-WebRequest -Uri $url -UseBasicParsing -Headers $Headers -UserAgent $UserAgent
# $VerbosePreference = $OriginalVerbosePreference
# WriteLog "Complete"
# # Parse the content of the relevant nested divs
# WriteLog "Parsing web content for models and download links"
# $html = $webContent.Content
# $nestedDivPattern = '<div id="ID0EBHFBH[1-8]" class="ocContentControlledByDropdown.*?">(.*?)</div>'
# $nestedDivMatches = [regex]::Matches($html, $nestedDivPattern, [System.Text.RegularExpressions.RegexOptions]::Singleline)
# $models = @()
# $modelPattern = '<p>(.*?)</p>\s*</td>\s*<td>\s*<p>\s*<a href="(.*?)"'
# foreach ($nestedDiv in $nestedDivMatches) {
# $nestedDivContent = $nestedDiv.Groups[1].Value
# $modelMatches = [regex]::Matches($nestedDivContent, $modelPattern)
# foreach ($match in $modelMatches) {
# $modelName = $match.Groups[1].Value
# $modelLink = $match.Groups[2].Value
# $models += [PSCustomObject]@{ Model = $modelName; Link = $modelLink }
# }
# }
# WriteLog "Parsing complete"
# # Validate the model
# $selectedModel = $models | Where-Object { $_.Model -eq $Model }
# if ($null -eq $selectedModel) {
# if ($VerbosePreference -ne 'Continue') {
# Write-Host "The model '$Model' was not found in the list of available models."
# Write-Host "Please run the script with the -Verbose switch to see the list of available models."
# }
# WriteLog "The model '$Model' was not found in the list of available models."
# WriteLog "Please select a model from the list below by number:"
# for ($i = 1; $i -lt $models.Count; $i++) {
# if ($VerbosePreference -ne 'Continue') {
# Write-Host "$i. $($models[$i].Model)"
# }
# WriteLog "$i. $($models[$i].Model)"
# }
# do {
# $selection = Read-Host "Enter the number of the model you want to select"
# WriteLog "User selected model number: $selection"
# if ($selection -match '^\d+$' -and [int]$selection -ge 0 -and [int]$selection -lt $models.Count) {
# $selectedModel = $models[$selection]
# } else {
# if ($VerbosePreference -ne 'Continue') {
# Write-Host "Invalid selection. Please try again."
# }
# WriteLog "Invalid selection. Please try again."
# }
# } while ($null -eq $selectedModel)
# }
# $Model = $selectedModel.Model
# WriteLog "Model: $Model"
# WriteLog "Download Page: $($selectedModel.Link)"
# # Follow the link to the download page and parse the script tag
# WriteLog "Getting download page content"
# $OriginalVerbosePreference = $VerbosePreference
# $VerbosePreference = 'SilentlyContinue'
# $downloadPageContent = Invoke-WebRequest -Uri $selectedModel.Link -UseBasicParsing -Headers $Headers -UserAgent $UserAgent
# $VerbosePreference = $OriginalVerbosePreference
# WriteLog "Complete"
# WriteLog "Parsing download page for file"
# $scriptPattern = '<script>window.__DLCDetails__={(.*?)}</script>'
# $scriptMatch = [regex]::Match($downloadPageContent.Content, $scriptPattern)
# if ($scriptMatch.Success) {
# $scriptContent = $scriptMatch.Groups[1].Value
# # Extract the download file information from the script tag
# $downloadFilePattern = '"name":"(.*?)",.*?"url":"(.*?)"'
# $downloadFileMatches = [regex]::Matches($scriptContent, $downloadFilePattern)
# $downloadLink = $null
# foreach ($downloadFile in $downloadFileMatches) {
# $fileName = $downloadFile.Groups[1].Value
# $fileUrl = $downloadFile.Groups[2].Value
# if ($fileName -match "Win$WindowsRelease") {
# $downloadLink = $fileUrl
# break
# }
# }
# if ($downloadLink) {
# WriteLog "Download Link for Windows ${WindowsRelease}: $downloadLink"
# # Create directory structure
# if (-not (Test-Path -Path $DriversFolder)) {
# WriteLog "Creating Drivers folder: $DriversFolder"
# New-Item -Path $DriversFolder -ItemType Directory -Force | Out-Null
# WriteLog "Drivers folder created"
# }
# $surfaceDriversPath = Join-Path -Path $DriversFolder -ChildPath $Make
# $modelPath = Join-Path -Path $surfaceDriversPath -ChildPath $Model
# if (-Not (Test-Path -Path $modelPath)) {
# WriteLog "Creating model folder: $modelPath"
# New-Item -Path $modelPath -ItemType Directory | Out-Null
# WriteLog "Complete"
# }
# # Download the file
# $filePath = Join-Path -Path $surfaceDriversPath -ChildPath ($fileName)
# WriteLog "Downloading $Model driver file to $filePath"
# Start-BitsTransferWithRetry -Source $downloadLink -Destination $filePath
# WriteLog "Download complete"
# # Determine file extension
# $fileExtension = [System.IO.Path]::GetExtension($filePath).ToLower()
# if ($fileExtension -eq ".msi") {
# # Extract the MSI file using an administrative install
# WriteLog "Extracting MSI file to $modelPath"
# $arguments = "/a `"$($filePath)`" /qn TARGETDIR=`"$($modelPath)`""
# Invoke-Process -FilePath "msiexec.exe" -ArgumentList $arguments
# WriteLog "Extraction complete"
# } elseif ($fileExtension -eq ".zip") {
# # Extract the ZIP file
# WriteLog "Extracting ZIP file to $modelPath"
# $ProgressPreference = 'SilentlyContinue'
# Expand-Archive -Path $filePath -DestinationPath $modelPath -Force
# $ProgressPreference = 'Continue'
# WriteLog "Extraction complete"
# } else {
# WriteLog "Unsupported file type: $fileExtension"
# }
# # Remove the downloaded file
# WriteLog "Removing $filePath"
# Remove-Item -Path $filePath -Force
# WriteLog "Complete"
# } else {
# WriteLog "No download link found for Windows $WindowsRelease."
# }
# } else {
# WriteLog "Failed to parse the download page for the MSI file."
# }
# }
function Get-MicrosoftDrivers { function Get-MicrosoftDrivers {
param ( param (
[string]$Make, [string]$Make,
@@ -558,23 +715,39 @@ function Get-MicrosoftDrivers {
$VerbosePreference = $OriginalVerbosePreference $VerbosePreference = $OriginalVerbosePreference
WriteLog "Complete" WriteLog "Complete"
# Parse the content of the relevant nested divs # Parse the HTML content
WriteLog "Parsing web content for models and download links" WriteLog "Parsing web content for models and download links"
$html = $webContent.Content $html = $webContent.Content
$nestedDivPattern = '<div id="ID0EBHFBH[1-8]" class="ocContentControlledByDropdown.*?">(.*?)</div>' $document = New-Object -ComObject "HTMLFILE"
$nestedDivMatches = [regex]::Matches($html, $nestedDivPattern, [System.Text.RegularExpressions.RegexOptions]::Singleline) $document.IHTMLDocument2_write($html)
$document.Close()
$models = @() $models = @()
$modelPattern = '<p>(.*?)</p>\s*</td>\s*<td>\s*<p>\s*<a href="(.*?)"'
foreach ($nestedDiv in $nestedDivMatches) { # Select all divs with class 'selectable-content-options__option-content'
$nestedDivContent = $nestedDiv.Groups[1].Value $divs = $document.getElementsByTagName("div") | Where-Object {
$modelMatches = [regex]::Matches($nestedDivContent, $modelPattern) $_.className -eq "selectable-content-options__option-content" -or $_.className -eq "selectable-content-options__option-content ocHidden"
}
foreach ($match in $modelMatches) { foreach ($div in $divs) {
$modelName = $match.Groups[1].Value $tables = $div.getElementsByTagName("table")
$modelLink = $match.Groups[2].Value foreach ($table in $tables) {
$models += [PSCustomObject]@{ Model = $modelName; Link = $modelLink } $rows = $table.getElementsByTagName("tr")
foreach ($row in $rows) {
$cells = $row.getElementsByTagName("td")
if ($cells.length -ge 2) {
$modelName = $cells[0].innerText.Trim()
$linkElement = $cells[1].getElementsByTagName("a")
if ($linkElement.length -gt 0) {
$modelLink = $linkElement[0].href
$models += [PSCustomObject]@{ Model = $modelName; Link = $modelLink }
} else {
# Handle cases with instructions instead of links
$modelLink = $cells[1].innerText.Trim()
$models += [PSCustomObject]@{ Model = $modelName; Link = $modelLink }
}
}
}
} }
} }
WriteLog "Parsing complete" WriteLog "Parsing complete"
@@ -590,19 +763,19 @@ function Get-MicrosoftDrivers {
WriteLog "The model '$Model' was not found in the list of available models." WriteLog "The model '$Model' was not found in the list of available models."
WriteLog "Please select a model from the list below by number:" WriteLog "Please select a model from the list below by number:"
for ($i = 1; $i -lt $models.Count; $i++) { for ($i = 0; $i -lt $models.Count; $i++) {
if ($VerbosePreference -ne 'Continue') { if ($VerbosePreference -ne 'Continue') {
Write-Host "$i. $($models[$i].Model)" Write-Host "$($i + 1). $($models[$i].Model)"
} }
WriteLog "$i. $($models[$i].Model)" WriteLog "$($i + 1). $($models[$i].Model)"
} }
do { do {
$selection = Read-Host "Enter the number of the model you want to select" $selection = Read-Host "Enter the number of the model you want to select"
WriteLog "User selected model number: $selection" WriteLog "User selected model number: $selection"
if ($selection -match '^\d+$' -and [int]$selection -ge 0 -and [int]$selection -lt $models.Count) { if ($selection -match '^\d+$' -and [int]$selection -ge 1 -and [int]$selection -le $models.Count) {
$selectedModel = $models[$selection] $selectedModel = $models[$selection - 1]
} else { } else {
if ($VerbosePreference -ne 'Continue') { if ($VerbosePreference -ne 'Continue') {
Write-Host "Invalid selection. Please try again." Write-Host "Invalid selection. Please try again."
@@ -698,6 +871,7 @@ function Get-MicrosoftDrivers {
WriteLog "Failed to parse the download page for the MSI file." WriteLog "Failed to parse the download page for the MSI file."
} }
} }
function Get-HPDrivers { function Get-HPDrivers {
[CmdletBinding()] [CmdletBinding()]
param ( param (