/ .pipelines / installPowertoys.ps1
installPowertoys.ps1
1 param( 2 [Parameter()] 3 [ValidateSet("Machine", "PerUser")] 4 [string]$InstallMode = "Machine" 5 ) 6 7 $ProgressPreference = 'SilentlyContinue' 8 9 # Get artifact path 10 $ArtifactPath = $ENV:BUILD_ARTIFACTSTAGINGDIRECTORY 11 if (-not $ArtifactPath) { 12 throw "BUILD_ARTIFACTSTAGINGDIRECTORY environment variable not set" 13 } 14 15 # Since we only download PowerToysSetup-*.exe files, we can directly find it 16 $Installer = Get-ChildItem -Path $ArtifactPath -Filter 'PowerToys*.exe' | Select-Object -First 1 17 18 if (-not $Installer) { 19 throw "PowerToys installer not found" 20 } 21 22 Write-Host "Installing PowerToys: $($Installer.Name)" 23 24 # Install PowerToys 25 $Process = Start-Process -Wait -FilePath $Installer.FullName -ArgumentList "/passive", "/norestart" -PassThru -NoNewWindow 26 27 if ($Process.ExitCode -eq 0 -or $Process.ExitCode -eq 3010) { 28 Write-Host "✅ PowerToys installation completed successfully" 29 } else { 30 throw "PowerToys installation failed with exit code: $($Process.ExitCode)" 31 } 32 33 # Verify installation 34 if ($InstallMode -eq "PerUser") { 35 if (Test-Path "${env:LOCALAPPDATA}\PowerToys\PowerToys.exe") { 36 Write-Host "✅ PowerToys verified at: ${env:LOCALAPPDATA}\PowerToys\PowerToys.exe" 37 } else { 38 throw "PowerToys installation verification failed" 39 } 40 } else { 41 if (Test-Path "${env:ProgramFiles}\PowerToys\PowerToys.exe") { 42 Write-Host "✅ PowerToys verified at: ${env:ProgramFiles}\PowerToys\PowerToys.exe" 43 } else { 44 throw "PowerToys installation verification failed" 45 } 46 }