mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Merge pull request #42 from rbalsleyMSFT/2407.2
Fixed Lenovo driver download issues
This commit is contained in:
@@ -903,69 +903,54 @@ function Get-LenovoDrivers {
|
|||||||
[int]$WindowsRelease
|
[int]$WindowsRelease
|
||||||
)
|
)
|
||||||
|
|
||||||
# Parse the Lenovo PSREF search page for machine types
|
|
||||||
function Get-LenovoPSREF {
|
function Get-LenovoPSREF {
|
||||||
param (
|
param (
|
||||||
[string]$ModelName
|
[string]$ModelName
|
||||||
)
|
)
|
||||||
|
|
||||||
$url = "https://psref.lenovo.com/search"
|
$url = "https://psref.lenovo.com/api/search/DefinitionFilterAndSearch/Suggest?kw=$ModelName"
|
||||||
WriteLog "Getting Lenovo PSREF page for model: $ModelName"
|
WriteLog "Querying Lenovo PSREF API for model: $ModelName"
|
||||||
$OriginalVerbosePreference = $VerbosePreference
|
$OriginalVerbosePreference = $VerbosePreference
|
||||||
$VerbosePreference = 'SilentlyContinue'
|
$VerbosePreference = 'SilentlyContinue'
|
||||||
$webContent = Invoke-WebRequest -Uri $url
|
$response = Invoke-WebRequest -Uri $url -UseBasicParsing -Headers $Headers -UserAgent $UserAgent
|
||||||
$VerbosePreference = $OriginalVerbosePreference
|
$VerbosePreference = $OriginalVerbosePreference
|
||||||
WriteLog "Complete"
|
WriteLog "Complete"
|
||||||
|
|
||||||
# Access the parsed HTML
|
$jsonResponse = $response.Content | ConvertFrom-Json
|
||||||
WriteLog "Parsing content"
|
|
||||||
$parsedHtml = $webContent.ParsedHtml
|
|
||||||
|
|
||||||
# Select the nodes you are interested in
|
|
||||||
$productNameNodes = $parsedHtml.getElementsByTagName("li") | Where-Object { $_.className -contains "productname_li" }
|
|
||||||
$products = @()
|
$products = @()
|
||||||
# Iterate through the nodes
|
foreach ($item in $jsonResponse.data) {
|
||||||
foreach ($product in $productNameNodes) {
|
$productName = $item.ProductName
|
||||||
$productA = $product.getElementsByTagName("a") | Where-Object { $_.tagName -eq "a" }
|
$machineTypes = $item.MachineType -split " / "
|
||||||
$innertext = @($productA.innertext) # Ensure innertext is treated as an array
|
|
||||||
$productName = $innertext[0]
|
foreach ($machineType in $machineTypes) {
|
||||||
|
if ($machineType -eq $ModelName) {
|
||||||
#if $productname contains 'Chromebook', skip the product
|
WriteLog "Model name entered is a matching machine type"
|
||||||
if ($productName -like '*Chromebook*') {
|
$products = @()
|
||||||
continue
|
|
||||||
}
|
|
||||||
$machineTypes = $innertext[1..($innertext.Count - 1)]
|
|
||||||
|
|
||||||
if ($innertext -match $ModelName) {
|
|
||||||
foreach ($machineType in $machineTypes) {
|
|
||||||
If ($machineType -eq $modelName) {
|
|
||||||
WriteLog "Model name entered is a matching machine type"
|
|
||||||
$products = @()
|
|
||||||
$products += [pscustomobject]@{
|
|
||||||
ProductName = $productName
|
|
||||||
MachineType = $machineType
|
|
||||||
}
|
|
||||||
WriteLog "Product Name: $productName Machine Type: $machineType"
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
$products += [pscustomobject]@{
|
$products += [pscustomobject]@{
|
||||||
ProductName = $productName
|
ProductName = $productName
|
||||||
MachineType = $machineType
|
MachineType = $machineType
|
||||||
}
|
}
|
||||||
|
WriteLog "Product Name: $productName Machine Type: $machineType"
|
||||||
|
return $products
|
||||||
|
}
|
||||||
|
$products += [pscustomobject]@{
|
||||||
|
ProductName = $productName
|
||||||
|
MachineType = $machineType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ,$products
|
return ,$products
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse the Lenovo PSREF page for the model
|
# Parse the Lenovo PSREF page for the model
|
||||||
$machineTypes = Get-LenovoPSREF -ModelName $Model
|
$machineTypes = Get-LenovoPSREF -ModelName $Model
|
||||||
if ($machineTypes.Count -eq 0) {
|
if ($machineTypes.ProductName.Count -eq 0) {
|
||||||
WriteLog "No machine types found for model: $Model"
|
WriteLog "No machine types found for model: $Model"
|
||||||
WriteLog "Enter a valid model or machine type in the -model parameter"
|
WriteLog "Enter a valid model or machine type in the -model parameter"
|
||||||
exit
|
exit
|
||||||
} elseif ($machineTypes.Count -eq 1) {
|
} elseif ($machineTypes.ProductName.Count -eq 1) {
|
||||||
$machineType = $machineTypes[0].MachineType
|
$machineType = $machineTypes[0].MachineType
|
||||||
$model = $machineTypes[0].ProductName
|
$model = $machineTypes[0].ProductName
|
||||||
} else {
|
} else {
|
||||||
@@ -973,7 +958,7 @@ function Get-LenovoDrivers {
|
|||||||
Write-Output "Multiple machine types found for model: $Model"
|
Write-Output "Multiple machine types found for model: $Model"
|
||||||
}
|
}
|
||||||
WriteLog "Multiple machine types found for model: $Model"
|
WriteLog "Multiple machine types found for model: $Model"
|
||||||
for ($i = 0; $i -lt $machineTypes.Count; $i++) {
|
for ($i = 0; $i -lt $machineTypes.ProductName.Count; $i++) {
|
||||||
if ($VerbosePreference -ne 'Continue'){
|
if ($VerbosePreference -ne 'Continue'){
|
||||||
Write-Output "$($i + 1). $($machineTypes[$i].ProductName) ($($machineTypes[$i].MachineType))"
|
Write-Output "$($i + 1). $($machineTypes[$i].ProductName) ($($machineTypes[$i].MachineType))"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user