2 setup-windows-steps.ps1 - every step the Windows setup can take, in one list.
4 Dot-sourced, never run: it defines functions and nothing else, so loading it
5 changes no state. It deliberately has no param block either - dot-sourcing
6 binds one in the CALLER's scope, which would reset the caller's own -Only and
7 -Skip to their defaults.
10 setup-windows-plan.ps1 shows it as the plan before anything happens,
11 and lets you choose; setup-windows.bat runs it first
12 setup-windows.bat takes the Runner 'bat' steps, as the planner hands
13 them over (it never reads this file itself)
14 setup-windows-with-uac.ps1 takes the 'uac' steps - the elevated half
15 setup-windows-no-uac.ps1 takes the 'user' steps - per-user configuration
17 THIS IS THE ONE PLACE a step's availability is decided. -X64Only, with its
18 reason, keeps a step off ARM64; -Admin keeps it off an account that cannot
19 elevate. The planner shows both as "[-]" rows with the reason, the batch file
20 prints the same reason in the log where the step would have run, and the two
21 halves apply them again when run on their own. This replaces the :x64only
22 subroutine that used to sit at the bottom of setup-windows.bat and the
23 $Arm64Dropped table in setup-windows-no-uac.ps1.
25 Adding a step: add a row below, in the order it runs, and gate the code that
26 does it on the same Id in the script its Runner names. The scripts check that
27 the two agree: an Id the catalog does not know is refused, and a catalog row
28 that nothing implements is reported rather than silently dropped.
31 function Get-SetupGroups {
32 # Display order is run order. The letter is what you type in the planner, or
33 # pass to -Only / -Skip, to take a whole group at once.
35 U = 'Per-user installs (winget, except Claude Code)'
36 M = 'Machine-wide installs (winget), then the WiX .NET tool'
37 E = 'Elevated setup (setup-windows-with-uac.ps1)'
38 C = 'Per-user configuration (setup-windows-no-uac.ps1), then Pillow'
42 function New-SetupStep {
44 [Parameter(Mandatory, Position = 0)] [string] $Id,
45 [Parameter(Mandatory, Position = 1)] [ValidateSet('U', 'M', 'E', 'C')] [string] $Group,
46 # Which script takes the step.
47 [Parameter(Mandatory, Position = 2)] [ValidateSet('bat', 'uac', 'user')] [string] $Runner,
48 # What the plan says the step does. For a winget step it follows the
49 # package id, so it only needs to add what the id does not say.
52 # Not on ARM64, because <this>. Shown in the plan and in the run log.
54 # Needs an account that can elevate: a machine-wide installer, or part
55 # of the elevated half.
57 # Steps this one builds on. Advisory only - the planner notes it when
58 # one of these is switched off, since it may already be installed.
59 [string[]] $Needs = @()
61 $shown = if (-not $Package) { $Text } elseif ($Text) { "$Package - $Text" } else { $Package }
74 function Get-SetupCatalog {
75 # Every step, in the order setup-windows.bat takes them. The long-form
76 # reasoning for each one stays in a comment beside the code that does it;
77 # the text here is what a person deciding needs to see.
78 param([bool] $IsArm64)
81 'Visual Studio 2026 Community, C++: MSVC for ARM64 + x86/x64, SDK 26100 (several GB)'
83 'Visual Studio 2022 Community, C++: MSVC for x86/x64 + ARM64, SDK 26100 (several GB)'
85 $rust = if ($IsArm64) {
86 'Rust stable-aarch64-pc-windows-msvc (native), installed and made the default'
88 'Rust stable-x86_64-pc-windows-msvc, installed and made the default'
92 # --- setup-windows.bat: per-user winget installs ---
93 # Not winget: recent Anthropic.ClaudeCode releases are broken through it.
94 New-SetupStep ClaudeCode U bat -Text 'Claude Code, native installer: irm https://claude.ai/install.ps1 | iex'
95 New-SetupStep Brave U bat -Package Brave.Brave `
96 -X64Only 'no ARM64 build, and Edge is in-box and native'
97 New-SetupStep Git U bat -Package Git.Git
98 New-SetupStep PowerShell U bat -Package Microsoft.PowerShell
99 New-SetupStep ProcessExplorer U bat -Package Microsoft.Sysinternals.ProcessExplorer
100 New-SetupStep ProcessMonitor U bat -Package Microsoft.Sysinternals.ProcessMonitor
101 New-SetupStep SDelete U bat -Package Microsoft.Sysinternals.SDelete
102 New-SetupStep VSCode U bat -Package Microsoft.VisualStudioCode
103 New-SetupStep WindowsTerminal U bat -Package Microsoft.WindowsTerminal
104 New-SetupStep Python U bat -Package Python.Python.3.13
105 New-SetupStep WinMerge U bat -Package WinMerge.WinMerge `
106 -X64Only 'its ARM64 build is machine-scope only; unelevated winget gets the x64 one'
107 New-SetupStep Ninja U bat -Package Ninja-build.Ninja -Text 'native; Visual Studio bundles an x64 one'
108 New-SetupStep LLVM U bat -Package LLVM.LLVM -Text 'upstream Clang, a second compiler beside clang-cl' `
109 -X64Only 'this box carries MSVC alone; no second Clang to cross-check'
110 New-SetupStep Rustup U bat -Package Rustlang.Rustup -Text 'the Rust toolchain manager, per-user; installs stable too'
111 New-SetupStep iPerf3 U bat -Package ar51an.iPerf3
112 # On ARM64 too, like iperf3: an x86-only build, but bound by the link to
113 # the device, not the CPU. See the comment beside it in setup-windows.bat.
114 New-SetupStep PlatformTools U bat -Package Google.PlatformTools -Text 'Android SDK Platform-Tools: adb, fastboot (an x86 build)'
115 New-SetupStep NASM U bat -Package NASM.NASM `
116 -X64Only 'x86/x64-only assembler; MSVC armasm64 is the native one'
117 New-SetupStep VirtualBox U bat -Package Oracle.VirtualBox -Text 'for the Windows 7 test VM' `
118 -X64Only 'no ARM64 host build, so no Windows 7 x86 test VM either'
120 # --- setup-windows.bat: machine-wide installers, despite running unelevated ---
121 New-SetupStep DotNetSdk M bat -Admin -Package Microsoft.DotNet.SDK.10 -Text 'for the WiX tooling'
122 New-SetupStep CMake M bat -Admin -Package Kitware.CMake -Text 'standalone, so a plain cmake works in any shell'
123 New-SetupStep AndroidGPUInspector M bat -Admin -Package Google.AndroidGPUInspector `
124 -X64Only 'x64-only build, and it profiles Android devices, not this box'
125 New-SetupStep AndroidStudio M bat -Admin -Package Google.AndroidStudio -Text 'only if missing; it updates itself' `
126 -X64Only 'Google publishes no Windows ARM64 build of Android Studio'
127 New-SetupStep OpenCppCoverage M bat -Admin -Package OpenCppCoverage.OpenCppCoverage -Text 'native line coverage' `
128 -X64Only 'it steps x86/x64 instructions, so it cannot cover an ARM64 binary'
129 New-SetupStep WiX M bat -Needs DotNetSdk `
130 -Text 'WiX 5.0.2 as a .NET global tool, pinned: 6.0 and later carry a maintenance-fee EULA'
132 # --- setup-windows-with-uac.ps1: the elevated half ---
133 New-SetupStep OpenSshClient E uac -Admin -Text 'OpenSSH Client capability (ssh.exe, and the libcrypto.dll rsync''s ssh.exe needs)'
134 New-SetupStep SshAgent E uac -Admin -Needs OpenSshClient -Text 'ssh-agent service: start automatically, and start it now'
135 New-SetupStep OpenSshServer E uac -Admin -Text 'OpenSSH Server: sshd automatic and running, inbound TCP 22 on all profiles'
136 New-SetupStep Rsync E uac -Admin -Needs OpenSshClient -Text 'rsync and its ssh.exe into C:\Tools\rsync, on the machine PATH'
137 New-SetupStep VisualStudio E uac -Admin -Text $vs
138 New-SetupStep VsClang E uac -Admin -Needs VisualStudio -Text 'Visual Studio Clang/LLVM toolset (clang-cl, for the ClangCL presets)' `
139 -X64Only 'by choice: this box carries MSVC alone'
140 New-SetupStep VsWinXP E uac -Admin -Needs VisualStudio -Text 'Visual Studio v141 + Windows XP targeting toolset' `
141 -X64Only 'v141 has no ARM64-hosted compiler; no XP targeting from Arm'
142 New-SetupStep Wdk E uac -Admin -Needs VisualStudio -Text 'Windows Driver Kit 10.0.26100 (pairs with SDK 26100)' `
143 -X64Only 'user-mode box; this WDK will not install beside VS 2026''s SDK'
144 New-SetupStep Wpt E uac -Admin -Text 'Windows Performance Toolkit (xperf, wpr, WPA); the Windows ADK if it is missing'
145 New-SetupStep VTune E uac -Admin -Text 'Intel VTune Profiler: report whether it is installed (installs nothing)'
147 # --- setup-windows-no-uac.ps1: per-user configuration ---
148 New-SetupStep WinMergePath C user -Needs WinMerge -Text 'WinMerge on the user PATH' `
149 -X64Only 'WinMerge is not installed on ARM64'
150 New-SetupStep VsWhere C user -Needs VisualStudio -Text 'vswhere.exe on the user PATH'
151 New-SetupStep BinSkim C user -Text 'BinSkim into %LOCALAPPDATA%\Programs\BinSkim, on the user PATH (100+ MB)' `
152 -X64Only 'the NuGet package publishes win-x64 only'
153 New-SetupStep GitConfig C user -Needs Git -Text 'global git: identity if filled in, core.sshCommand to a Win32-OpenSSH client'
154 New-SetupStep NinjaPath C user -Needs Ninja -Text 'the native ninja first on the user PATH'
155 New-SetupStep LlvmPath C user -Needs LLVM -Text 'upstream LLVM on the user PATH' `
156 -X64Only 'LLVM is not installed on ARM64'
157 New-SetupStep RustToolchain C user -Needs Rustup, VisualStudio -Text $rust
158 New-SetupStep AndroidSdk C user -Needs AndroidStudio `
159 -Text 'Android SDK, per-user: latest platform + build-tools; accepts the SDK licences' `
160 -X64Only 'its Windows build tools are x86/x64 only, as is Android Studio'
161 New-SetupStep ArchAudit C user -Text 'architecture audit: native or emulated, for every tool (read-only)'
163 # --- setup-windows.bat, after both halves ---
164 New-SetupStep Pillow C bat -Needs Python -Text 'pip install Pillow into the newest Python'
168 function Get-SetupStepBlocker {
169 # Why this step cannot run on this machine at all, or $null if it can.
170 # Architecture first: an x64-only step is off ARM64 before elevation is even
171 # consulted, which is the more useful reason to show.
172 param($Step, [bool] $IsArm64, [string] $Elevation)
173 if ($IsArm64 -and $Step.X64Only) { return "not on ARM64 - $($Step.X64Only)" }
174 if ($Elevation -eq 'NOLUA' -and $Step.Admin) {
175 return 'needs an administrator - this account cannot elevate'
180 function Split-SetupNames {
181 # `powershell -File` hands a whole "A,B,C" to an array parameter as ONE
182 # string, so split here and accept either spelling.
183 param([string[]] $Value)
184 @($Value | ForEach-Object { $_ -split '[,\s]+' } | Where-Object { $_ })
187 function Resolve-SetupStepNames {
188 # Step ids (case-insensitive) or group letters, as typed, to step ids.
189 # Anything else is an error: a mistyped -Skip that was quietly ignored would
190 # install exactly what you asked it not to.
191 param([string[]] $Names, [object[]] $Steps, [hashtable] $Aliases = @{})
192 $groups = @((Get-SetupGroups).Keys)
193 foreach ($name in (Split-SetupNames $Names)) {
194 if ($Aliases.ContainsKey($name)) { $name = $Aliases[$name] }
195 $hit = @($Steps | Where-Object { $_.Id -eq $name })
196 if (-not $hit) { $hit = @($Steps | Where-Object { $_.Group -eq $name }) }
197 if ($hit) { $hit.Id; continue }
198 # A real group with no steps in this script's share of the catalog.
199 if ($groups -contains $name) { continue }
200 throw "Unknown step '$name'. The steps are: $($Steps.Id -join ', '). Groups: $($groups -join ', ')."
204 function Resolve-SetupSelection {
205 # The plan: one row per step, in run order, saying whether it is selected
206 # and - when it cannot run on this machine at all - why not.
208 # -Only $null means "everything that can run"; an empty -Only means nothing.
211 [AllowNull()] [string[]] $Only,
212 [string[]] $Skip = @(),
213 [hashtable] $Aliases = @{},
217 $want = if ($null -eq $Only) { @($Steps.Id) } else { @(Resolve-SetupStepNames $Only $Steps $Aliases) }
218 $drop = @(Resolve-SetupStepNames $Skip $Steps $Aliases)
219 $named = @(Split-SetupNames $Only | ForEach-Object { if ($Aliases.ContainsKey($_)) { $Aliases[$_] } else { $_ } })
220 foreach ($s in $Steps) {
221 $why = Get-SetupStepBlocker $s $IsArm64 $Elevation
222 if ($why -and $named -contains $s.Id) {
223 Write-Warning "$($s.Id) was asked for but cannot run here: $why"
229 Selected = (-not $why) -and ($want -contains $s.Id) -and ($drop -notcontains $s.Id)
234 function Write-SetupPlan {
235 # The short form of the plan, for the two halves: what this script will do
236 # and what it will not, before it does any of it.
237 param([object[]] $Plan, [string] $Title)
238 Write-Host "`n==> $Title" -ForegroundColor Cyan
239 foreach ($p in $Plan) {
241 Write-Host (' run {0,-14} {1}' -f $p.Id, $p.Step.Text)
243 $why = if ($p.Why) { $p.Why } else { 'not selected' }
244 Write-Host (' skip {0,-14} {1}' -f $p.Id, $why) -ForegroundColor DarkGray
249 function Confirm-SetupPlan {
250 # $true to go ahead, $false if declined, $null if there is no one to ask.
252 # Never assumes yes on its own. A run with no console behind it - piped,
253 # scheduled, a non-interactive ssh command - stops after printing the plan,
254 # and says how to run it unattended (-Yes) on purpose.
255 param([switch] $Yes, [int] $Count)
256 if ($Yes) { return $true }
257 if ([Console]::IsInputRedirected) {
258 Write-Host ' No console to ask on, so nothing has been done. Re-run with -Yes to take' -ForegroundColor Yellow
259 Write-Host ' the steps marked "run" unattended.' -ForegroundColor Yellow
262 $answer = Read-Host " Take the $Count step(s) marked run? [Y/n]"
263 if ($answer -match '^\s*(y|yes)?\s*$') { return $true }
264 Write-Host ' Nothing done.'