Clean up the Get-MicrosoftDrivers old code and version change

This commit is contained in:
rbalsleyMSFT
2024-09-17 14:03:43 -07:00
parent fb0a630bfd
commit 5dcdd2c36f
+1 -158
View File
@@ -336,7 +336,7 @@ param(
[bool]$AllowExternalHardDiskMedia, [bool]$AllowExternalHardDiskMedia,
[bool]$PromptExternalHardDiskMedia = $true [bool]$PromptExternalHardDiskMedia = $true
) )
$version = '2409.2' $version = '2410.1'
#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,163 +541,6 @@ 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,