From 561ec98741b7986a3d0f224faf3e8b6eb241dfc8 Mon Sep 17 00:00:00 2001 From: blue Date: Sat, 15 Jun 2019 19:12:48 +0100 Subject: [PATCH] Add progress messages during usage With $ProgressPreference = "SilentlyContinue" set, the script often looks like it's hung. Inform the user what's going on more often, particularly for slow actions. --- Get-Bootcamp.ps1 | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Get-Bootcamp.ps1 b/Get-Bootcamp.ps1 index 918d47a..9828d04 100644 --- a/Get-Bootcamp.ps1 +++ b/Get-Bootcamp.ps1 @@ -19,11 +19,15 @@ if (!(Test-Path $OutputDir)) { New-Item -Path $OutputDir -ItemType Directory -Fo $7z = "$env:ProgramFiles\7-Zip\7z.exe" if (Test-Path $7z) { $7zInstalled = $true } if ([version](Get-ItemProperty $7z).VersionInfo.FileVersion -lt 15.14) { + Write-Host "7-Zip not installed, will install and remove." Invoke-WebRequest -Uri $SEVENZIP_URL -OutFile "$OutputDir\$($SEVENZIP_URL.Split('/')[-1])" -ErrorAction Stop Start-Process -FilePath $env:SystemRoot\System32\msiexec.exe -ArgumentList "/i $OutputDir\$($SEVENZIP_URL.Split('/')[-1]) /qb- /norestart" -Wait -Verbose } +Write-Host "Using model: $Model" + # Read data from sucatalog and find all Bootcamp ESD's +Write-Host "Downloading software update catalog..." [xml]$sucatalog = Invoke-WebRequest -Uri $SUCATALOG_URL -Method Get -ErrorAction Stop $sucatalog.plist.dict.dict.dict | Where-Object { $_.String -match "Bootcamp" } | ForEach-Object { # Search dist files to find supported models, using regex match to find models in dist files - stole regex from brigadier's source @@ -32,24 +36,27 @@ $sucatalog.plist.dict.dict.dict | Where-Object { $_.String -match "Bootcamp" } | $distXML = (Invoke-RestMethod -Uri $distURL).InnerXml $SupportedModels = [regex]::Matches($distXML,$modelRegex).Value if ($SupportedModels -contains $Model) { - $version = [regex]::Match($distURL,"(\d{3}-\d{5})").Value - Write-Output "Found supported ESD: $Version" + $version = [regex]::Match($distURL,"(\d{3}-\d{4,5})").Value + Write-Output "Found supported ESD: $Version, posted $($_.Date)" [array]$bootcamplist += $_ } } if ($bootcamplist.Length -gt 1) { - Write-warning "Found more than 1 supported Bootcamp ESD. Selecting newest based on posted date which may not always be correct" + Write-Host "Found more than 1 supported Bootcamp ESD. Selecting newest based on posted date which may not always be correct" } $esd = $bootcamplist | Sort-Object -Property Date | Select-Object -Last 1 # Build a hash table of the package's properties from the XML $package = $esd.array.dict.selectnodes('key') | ForEach-Object {@{$($_.'#text') = $($_.nextsibling.'#text')}} $package += @{'ESDVersion' = $Version} -$download = $package.URL +Write-Host "Selected $($package.ESDVersion) as it's the most recently posted." # Download the BootCamp ESD -Start-BitsTransfer -Source $download -Destination "$OutputDir\BootCampESD.pkg" -ErrorAction Stop +Write-Host "Starting download from $($package.URL)" +Start-BitsTransfer -Source $package.URL -Destination "$OutputDir\BootCampESD.pkg" -ErrorAction Stop +Write-Host "Download complete" if (Test-Path -Path "$OutputDir\BootCampESD.pkg") { # Extract the bootcamp installer + Write-Host "Extracting..." Invoke-Command -ScriptBlock { & $7z -o"$OutputDir" -y e "$OutputDir\BootCampESD.pkg" & $7z -o"$OutputDir" -y e "$OutputDir\Payload~"