mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Improves ADK FWLink resolution for robustness
Refactors the ADK URL retrieval logic to let `Invoke-WebRequest` handle the forward link redirection directly. This approach is more reliable than manually parsing the redirect response. Adds a try/catch block to provide better error handling and logging during the URL resolution process.
This commit is contained in:
@@ -1648,20 +1648,29 @@ function Get-ADKURL {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
# Retrieve headers of the FWlink URL
|
# Let Invoke-WebRequest handle the redirect and get the final URL.
|
||||||
$OriginalVerbosePreference = $VerbosePreference
|
try {
|
||||||
$VerbosePreference = 'SilentlyContinue'
|
$OriginalVerbosePreference = $VerbosePreference
|
||||||
$FWLinkRequest = Invoke-WebRequest -Uri $ADKFWLink -Method Head -MaximumRedirection 0 -ErrorAction SilentlyContinue
|
$VerbosePreference = 'SilentlyContinue'
|
||||||
$VerbosePreference = $OriginalVerbosePreference
|
# Allow one redirection to get the final URL from the fwlink
|
||||||
|
$response = Invoke-WebRequest -Uri $ADKFWLink -Method Head -MaximumRedirection 1 -Headers $Headers -UserAgent $UserAgent
|
||||||
if ($FWLinkRequest.StatusCode -ne 302) {
|
$VerbosePreference = $OriginalVerbosePreference
|
||||||
WriteLog "Failed to retrieve ADK download URL. Unexpected status code: $($FWLinkRequest.StatusCode)"
|
|
||||||
return
|
# The final URL after redirection is in the ResponseUri property of the BaseResponse's RequestMessage.
|
||||||
|
$ADKUrl = $response.BaseResponse.RequestMessage.RequestUri.AbsoluteUri
|
||||||
|
|
||||||
|
if ($null -eq $ADKUrl) {
|
||||||
|
WriteLog "Could not determine final ADK download URL after redirection."
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
|
||||||
|
WriteLog "Resolved ADK download URL to: $ADKUrl"
|
||||||
|
return $ADKUrl
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
WriteLog "An error occurred while resolving the ADK FWLink: $($_.Exception.Message)"
|
||||||
|
throw
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get the ADK link redirected to by the FWlink
|
|
||||||
$ADKUrl = $FWLinkRequest.Headers.Location
|
|
||||||
return $ADKUrl
|
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
WriteLog $_
|
WriteLog $_
|
||||||
|
|||||||
Reference in New Issue
Block a user