[CmdletBinding()]
param(
[switch]$Download,
[string]$Destination = (Get-Location).Path
)
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$base = "https://www.zebra.com"
$pagePath = "/content/zebra1/us/en/support-downloads/software/printer-software/zebra-designer-3-downloads"
$uri = "$base/content/servlet/supportdownload/downloadsearch?pagePath=$pagePath"
$response = Invoke-RestMethod -Uri $uri -UserAgent "Mozilla/5.0"
$results = foreach ($item in $response[0].Download) {
foreach ($version in $item.versionDownloadReferences) {
foreach ($file in $version.listingDownloadFiles) {
[pscustomobject]@{
Version = ($version.downloadShortDisplayTitle -replace "^ZebraDesigner\s*", "")
FileName = $file.title
Size = $file.size
Url = "$base$($file.id)"
}
}
}
}
if (-not $results) {
throw "Geen downloads gevonden in het antwoord van zebra.com."
}
# Hoogste versienummer eerst
$latest = $results |
Sort-Object { try { [version]$_.Version } catch { [version]"0.0" } } -Descending |
Select-Object -First 1
$latest
if ($Download) {
$target = Join-Path $Destination $latest.FileName
Write-Host "Downloaden naar $target ..."
Invoke-WebRequest -Uri $latest.Url -OutFile $target -UserAgent "Mozilla/5.0"
Write-Host "Klaar: $((Get-Item $target).Length) bytes"
}
Download and install:
[CmdletBinding()]
param(
[string]$WorkDir = (Join-Path $env:TEMP "ZebraDesigner3"),
[switch]$DownloadOnly,
[switch]$Force
)
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$base = "https://www.zebra.com"
$pagePath = "/content/zebra1/us/en/support-downloads/software/printer-software/zebra-designer-3-downloads"
$uri = "$base/content/servlet/supportdownload/downloadsearch?pagePath=$pagePath"
# --- Nieuwste versie opzoeken ---
$response = Invoke-RestMethod -Uri $uri -UserAgent "Mozilla/5.0"
$results = foreach ($item in $response[0].Download) {
foreach ($version in $item.versionDownloadReferences) {
foreach ($file in $version.listingDownloadFiles) {
[pscustomobject]@{
Version = ($version.downloadShortDisplayTitle -replace "^ZebraDesigner\s*", "")
FileName = $file.title
Url = "$base$($file.id)"
}
}
}
}
if (-not $results) {
throw "Geen downloads gevonden in het antwoord van zebra.com."
}
$latest = $results |
Where-Object { $_.FileName -like "*.zip" } |
Sort-Object { try { [version]$_.Version } catch { [version]"0.0" } } -Descending |
Select-Object -First 1
Write-Host "Nieuwste versie: $($latest.Version) ($($latest.FileName))"
# --- Geinstalleerde versie controleren ---
$uninstallKeys = @(
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
$installed = Get-ItemProperty $uninstallKeys -ErrorAction SilentlyContinue |
Where-Object { $_.DisplayName -like "ZebraDesigner 3*" -and $_.DisplayName -notlike "*Developer*" } |
Select-Object -First 1
if ($installed -and -not $Force -and -not $DownloadOnly) {
Write-Host "Geinstalleerd: $($installed.DisplayName) $($installed.DisplayVersion)"
try {
if ([version]$installed.DisplayVersion -ge [version]$latest.Version) {
Write-Host "Al up-to-date, niets te doen."
exit 0
}
} catch {
Write-Warning "Kan geinstalleerde versie '$($installed.DisplayVersion)' niet vergelijken, ga door met installeren."
}
}
# --- Downloaden ---
New-Item -ItemType Directory -Force -Path $WorkDir | Out-Null
$zipPath = Join-Path $WorkDir $latest.FileName
$extractDir = Join-Path $WorkDir ([IO.Path]::GetFileNameWithoutExtension($latest.FileName))
Write-Host "Downloaden: $($latest.Url)"
$sw = [Diagnostics.Stopwatch]::StartNew()
$curl = Get-Command curl.exe -ErrorAction SilentlyContinue
if ($curl) {
& $curl.Source -sSfL -A "Mozilla/5.0" -o $zipPath $latest.Url
if ($LASTEXITCODE -ne 0) { throw "curl.exe download mislukt (exitcode $LASTEXITCODE)." }
} else {
Invoke-WebRequest -Uri $latest.Url -OutFile $zipPath -UserAgent "Mozilla/5.0" -UseBasicParsing
}
Write-Host ("Gedownload: {0:N1} MB in {1:N0}s" -f ((Get-Item $zipPath).Length / 1MB), $sw.Elapsed.TotalSeconds)
# --- Uitpakken ---
if (Test-Path $extractDir) { Remove-Item $extractDir -Recurse -Force }
Expand-Archive -Path $zipPath -DestinationPath $extractDir -Force
$installer = Get-ChildItem -Path $extractDir -Filter "zebradesigner3*.exe" -Recurse | Select-Object -First 1
if (-not $installer) {
throw "Geen zebradesigner3*.exe gevonden in $zipPath."
}
$signature = Get-AuthenticodeSignature $installer.FullName
if ($signature.Status -ne "Valid" -or $signature.SignerCertificate.Subject -notlike "*O=Zebra Technologies Corporation*") {
throw "Ongeldige handtekening op $($installer.Name): $($signature.Status) / $($signature.SignerCertificate.Subject)"
}
Write-Host "Installer: $($installer.FullName) (handtekening OK)"
if ($DownloadOnly) {
exit 0
}
# --- Stil installeren (InstallAware: /s = silent, /l= = logbestand) ---
$principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
throw "Installeren vereist administratorrechten. Start PowerShell als administrator."
}
$logPath = Join-Path $WorkDir "install-$($latest.Version).log"
Write-Host "Installeren (log: $logPath) ..."
$process = Start-Process -FilePath $installer.FullName -ArgumentList "/s", "/l=`"$logPath`"" -Wait -PassThru
if ($process.ExitCode -ne 0) {
throw "Installatie mislukt met exitcode $($process.ExitCode). Zie $logPath"
}
$installed = Get-ItemProperty $uninstallKeys -ErrorAction SilentlyContinue |
Where-Object { $_.DisplayName -like "ZebraDesigner 3*" -and $_.DisplayName -notlike "*Developer*" } |
Select-Object -First 1
if ($installed) {
Write-Host "Geinstalleerd: $($installed.DisplayName) $($installed.DisplayVersion)"
} else {
Write-Warning "Installer gaf exitcode 0, maar ZebraDesigner 3 staat niet in het register."
}
# --- Opruimen ---
Remove-Item $zipPath, $extractDir -Recurse -Force -ErrorAction SilentlyContinue
exit 0