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.
This commit is contained in:
blue 2019-06-15 19:12:48 +01:00
parent a55697dadc
commit 561ec98741

View file

@ -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~"