Club PC setup

Win+R, paste, Ctrl+Shift+Enter (runs as admin):

powershell -ep bypass -c "irm pc.cuberg.dev | iex"

Or in an admin PowerShell: irm pc.cuberg.dev | iex

Script
# pc.cuberg.dev - one-shot setup for a (diskless) computer-club PC.
# Run:  Win+R -> powershell -ep bypass -c "irm pc.cuberg.dev | iex"  -> Ctrl+Shift+Enter (admin)
# Never reboots, never signs out. Every step is independent: one failure does not stop the rest.

& {
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'   # Invoke-WebRequest is 10x slower with the progress bar in PS 5.1
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$Self = 'https://pc.cuberg.dev'
$me = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
if (-not $me.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    Write-Host 'Not admin - asking for elevation...' -ForegroundColor Yellow
    Start-Process powershell.exe -Verb RunAs -ArgumentList '-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', "irm $Self | iex"
    return
}

$Work = Join-Path $env:TEMP 'club-setup'
New-Item -ItemType Directory -Force $Work | Out-Null
try { Start-Transcript -Path (Join-Path $Work 'setup.log') -Force | Out-Null } catch {}

$Results = [ordered]@{}
function Step([string]$Name, [scriptblock]$Body) {
    Write-Host "`n== $Name" -ForegroundColor Cyan
    try { $r = & $Body; $Results[$Name] = if ($r) { "OK  $r" } else { 'OK' } }
    catch { $Results[$Name] = "FAIL  $($_.Exception.Message)"; Write-Host "   $($_.Exception.Message)" -ForegroundColor Red }
}
function Say([string]$m) { Write-Host "   $m" }

# ---------- what to install ----------
$UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) club-setup'
$Ext = [ordered]@{
    'fjoaledfpmneenckfbpdfhkmimnjocfa' = 'NordVPN'
    'gejiddohjgogedgjnonbofjigllpkmbf' = '1Password Nightly'
}

function Find-Chrome {
    foreach ($p in "$env:ProgramFiles\Google\Chrome\Application\chrome.exe",
                   "${env:ProgramFiles(x86)}\Google\Chrome\Application\chrome.exe",
                   "$env:LOCALAPPDATA\Google\Chrome\Application\chrome.exe") { if (Test-Path $p) { return $p } }
}
function Find-Steam {
    $p = (Get-ItemProperty 'HKCU:\Software\Valve\Steam' -ErrorAction SilentlyContinue).SteamExe
    if ($p -and (Test-Path $p)) { return (Resolve-Path $p).Path }
    foreach ($k in 'HKLM:\SOFTWARE\WOW6432Node\Valve\Steam', 'HKLM:\SOFTWARE\Valve\Steam') {
        $d = (Get-ItemProperty $k -ErrorAction SilentlyContinue).InstallPath
        if ($d -and (Test-Path "$d\steam.exe")) { return "$d\steam.exe" }
    }
    if (Test-Path "${env:ProgramFiles(x86)}\Steam\steam.exe") { return "${env:ProgramFiles(x86)}\Steam\steam.exe" }
}

# ---------- parallel downloads ----------
function Start-Download([string]$Url, [string]$Name) {
    $path = Join-Path $Work $Name
    Remove-Item $path -Force -ErrorAction SilentlyContinue
    $wc = New-Object Net.WebClient
    $wc.Headers['User-Agent'] = $UA
    [pscustomobject]@{ Url = $Url; Path = $path; Task = $wc.DownloadFileTaskAsync([Uri]$Url, $path); Client = $wc }
}
function Wait-Download($d, [int]$TimeoutSec = 900) {
    if (-not $d) { throw 'download was not started' }
    $ok = try { $d.Task.Wait($TimeoutSec * 1000) }
          catch { throw "download failed: $($d.Url): $($_.Exception.GetBaseException().Message)" }
    if (-not $ok) { $d.Client.CancelAsync(); throw "download timed out: $($d.Url)" }
    if ((Get-Item $d.Path).Length -lt 10KB) { throw "download too small: $($d.Url)" }
    $d.Path
}

$S = @{ Chrome = (Find-Chrome); Steam = (Find-Steam) }   # shared state (steps run in child scopes)
$discordUpdate = "$env:LOCALAPPDATA\Discord\Update.exe"

Write-Host 'Starting downloads...' -ForegroundColor Cyan
$DL = @{}
$DL.Discord = if (-not (Test-Path $discordUpdate)) {
    Start-Download 'https://discord.com/api/downloads/distributions/app/installers/latest?channel=stable&platform=win&arch=x64' 'DiscordSetup.exe' }
$DL.Vencord = Start-Download 'https://github.com/Vencord/Installer/releases/latest/download/VencordInstallerCli.exe' 'VencordInstallerCli.exe'
function Get-PrismUrl {
    $gh = 'https://api.github.com/repos/PrismLauncher/PrismLauncher'
    try {
        # Prism has no push nightlies any more: develop is built by the merge queue. Newest green run -> nightly.link.
        $run = (Invoke-RestMethod "$gh/actions/workflows/build.yml/runs?event=merge_group&status=success&per_page=1" -UserAgent $UA).workflow_runs[0]
        $art = (Invoke-RestMethod "$gh/actions/runs/$($run.id)/artifacts?per_page=100" -UserAgent $UA).artifacts |
            Where-Object { $_.name -match '^PrismLauncher-Windows-MSVC-Portable-' -and -not $_.expired } | Select-Object -First 1
        if (-not $art) { throw 'no Windows artifact in the newest run' }
        $S.PrismVer = "nightly $($run.head_sha.Substring(0,7)) ($($run.created_at))"
        return "https://nightly.link/PrismLauncher/PrismLauncher/actions/runs/$($run.id)/$($art.name).zip"
    } catch { Write-Host "   Prism nightly lookup failed ($($_.Exception.Message)) - using latest release" -ForegroundColor Yellow }
    try {
        $rel = Invoke-RestMethod "$gh/releases/latest" -UserAgent $UA
        $S.PrismVer = "release $($rel.tag_name)"
        return ($rel.assets | Where-Object { $_.name -match '^PrismLauncher-Windows-MSVC-Portable-.*\.zip$' } | Select-Object -First 1).browser_download_url
    } catch { Write-Host "   Prism release lookup failed: $($_.Exception.Message)" -ForegroundColor Red }
}
$S.PrismUrl = Get-PrismUrl
$DL.Prism = if ($S.PrismUrl) { Start-Download $S.PrismUrl 'prism.zip' }
$DL.VCRedist = if (-not (Test-Path "$env:windir\System32\vcruntime140_1.dll")) {
    Start-Download 'https://aka.ms/vs/17/release/vc_redist.x64.exe' 'vc_redist.x64.exe' }
$S.OnePasswordUrl = try {
    # newest Nightly MSI from 1Password's release history (newest first); fallback: stable
    $h = (Invoke-WebRequest 'https://app-updates.agilebits.com/product_history/OPW8' -UseBasicParsing -UserAgent $UA).Content
    $m = [regex]::Match($h, 'https://c\.1password\.com/dist/1P/win8/1PasswordSetup-[\d.-]+\.NIGHTLY\.msi')
    if ($m.Success) { $m.Value } else { throw 'no nightly link' }
} catch { Write-Host "   1Password nightly lookup failed - using stable" -ForegroundColor Yellow; 'https://downloads.1password.com/win/1PasswordSetup-latest.msi' }
$DL.OnePassword = Start-Download $S.OnePasswordUrl '1PasswordSetup.msi'
$DL.Chrome = if (-not $S.Chrome) { Start-Download 'https://dl.google.com/dl/chrome/install/googlechromestandaloneenterprise64.msi' 'chrome.msi' }
$DL.Steam = if (-not $S.Steam) { Start-Download 'https://cdn.akamai.steamstatic.com/client/installer/SteamSetup.exe' 'SteamSetup.exe' }

# ---------- language (no reboot, no sign-out) ----------
Step 'Languages: English + Russian only, Chinese removed' {
    $list = New-WinUserLanguageList 'en-US'
    $list.Add('ru-RU')
    Set-WinUserLanguageList $list -Force
    Set-WinDefaultInputMethodOverride -InputTip '0409:00000409'
    try { Set-Culture en-US } catch { Say "Set-Culture: $($_.Exception.Message)" }
    $left = (Get-WinUserLanguageList | ForEach-Object LanguageTag) -join ', '
    if ($left -match 'zh') { throw "Chinese still present: $left" }
    "input languages: $left"
}

# ---------- Steam language ----------
Step 'Steam: English' {
    $k = 'HKCU:\Software\Valve\Steam'
    if (-not (Test-Path $k)) { New-Item $k | Out-Null }
    Set-ItemProperty $k -Name Language -Value 'english'
    if ($S.Steam -and (Get-Process steam -ErrorAction SilentlyContinue)) {
        Say 'Steam is running - shutting it down so the language applies'
        Start-Process $S.Steam -ArgumentList '-shutdown'
        $t = 0; while ((Get-Process steam -ErrorAction SilentlyContinue) -and $t -lt 20) { Start-Sleep 1; $t++ }
        Get-Process steam -ErrorAction SilentlyContinue | Stop-Process -Force
    }
}

# ---------- Chrome ----------
Step 'Chrome: policies (English UI, NordVPN + 1Password Nightly extensions)' {
    $pol = 'HKLM:\SOFTWARE\Policies\Google\Chrome'
    if (-not (Test-Path $pol)) { New-Item $pol -Force | Out-Null }
    Set-ItemProperty $pol -Name ApplicationLocaleValue -Value 'en-US'
    $cur = (Get-ItemProperty $pol -ErrorAction SilentlyContinue).ExtensionSettings
    $set = if ($cur) { $cur | ConvertFrom-Json } else { New-Object psobject }
    foreach ($id in $Ext.Keys) {
        $set | Add-Member -Force -NotePropertyName $id -NotePropertyValue ([ordered]@{
            installation_mode = 'normal_installed'; update_url = 'https://clients2.google.com/service/update2/crx' })
    }
    Set-ItemProperty $pol -Name ExtensionSettings -Value ($set | ConvertTo-Json -Depth 6 -Compress)
    # in case the club blocks extensions with ExtensionInstallBlocklist=*
    $allow = "$pol\ExtensionInstallAllowlist"
    if (-not (Test-Path $allow)) { New-Item $allow | Out-Null }
    $vals = (Get-Item $allow).GetValueNames() | ForEach-Object { (Get-ItemProperty $allow).$_ }
    $n = @((Get-Item $allow).GetValueNames() | Where-Object { $_ -match '^\d+$' } | ForEach-Object { [int]$_ }) + 0 | Measure-Object -Maximum
    $i = [int]$n.Maximum
    foreach ($id in $Ext.Keys) { if ($vals -notcontains $id) { $i++; Set-ItemProperty $allow -Name "$i" -Value $id } }
    ($Ext.Values -join ', ')
}

Step 'Chrome: install' {
    if ($S.Chrome) { return "already installed: $($S.Chrome)" }
    $msi = Wait-Download $DL.Chrome
    $p = Start-Process msiexec.exe -ArgumentList '/i', "`"$msi`"", '/qn', '/norestart' -Wait -PassThru
    if ($p.ExitCode -notin 0, 3010, 1641) { throw "msiexec exit $($p.ExitCode)" }
    $S.Chrome = Find-Chrome
    if (-not $S.Chrome) { throw 'chrome.exe not found after install' }
    $S.Chrome
}

# ---------- Discord + Vencord + OpenAsar ----------
function Get-DiscordApp { Get-ChildItem "$env:LOCALAPPDATA\Discord" -Directory -Filter 'app-*' -ErrorAction SilentlyContinue |
        Sort-Object { [version]($_.Name -replace '^app-', '') } | Select-Object -Last 1 }

Step 'Discord: install / update' {
    $t0 = Get-Date
    if (Test-Path $discordUpdate) {
        Start-Process $discordUpdate -ArgumentList '--processStart', 'Discord.exe'   # lets it apply pending updates
        $how = 'existing install updated'
    } else {
        $p = Start-Process (Wait-Download $DL.Discord) -ArgumentList '-s' -Wait -PassThru   # silent: blocks, does not launch
        if (-not (Test-Path $discordUpdate)) { throw "Discord setup failed (exit $($p.ExitCode))" }
        Start-Process $discordUpdate -ArgumentList '--processStart', 'Discord.exe'          # first run: host update + modules
        $how = 'installed'
    }
    # Discord may update its host once (new app-* folder) and then downloads its modules. Vencord must patch the
    # final app-* folder: wait >= 25 s and until the newest one has discord_desktop_core.
    $deadline = $t0.AddMinutes(5)
    do {
        Start-Sleep 3
        $app = Get-DiscordApp
        $core = if ($app) {
            Get-ChildItem "$($app.FullName)\modules" -Directory -Filter 'discord_desktop_core*' -ErrorAction SilentlyContinue |
                Get-ChildItem -Recurse -File -ErrorAction SilentlyContinue | Select-Object -First 1 }
    } until (($core -and ((Get-Date) - $t0).TotalSeconds -ge 25) -or (Get-Date) -gt $deadline)
    if (-not $app) { throw 'Discord did not finish installing in 5 min' }
    if (-not $core) { Say 'Discord modules still downloading after 5 min - patching anyway' }
    "$how, $($app.Name)"
}

Step 'Discord: Vencord + OpenAsar' {
    $cli = Wait-Download $DL.Vencord
    Get-Process Discord -ErrorAction SilentlyContinue | Stop-Process -Force
    Start-Sleep 2
    $p = Start-Process $cli -ArgumentList '-install', '-branch', 'stable' -Wait -PassThru -NoNewWindow
    if ($p.ExitCode -ne 0) { throw "Vencord installer exit $($p.ExitCode)" }
    Get-Process Discord -ErrorAction SilentlyContinue | Stop-Process -Force
    Start-Sleep 2
    $p = Start-Process $cli -ArgumentList '-install-openasar', '-branch', 'stable' -Wait -PassThru -NoNewWindow
    if ($p.ExitCode -ne 0) { Say "OpenAsar installer exit $($p.ExitCode) (it exits non-zero if OpenAsar is already there)" }
    Get-Process Discord -ErrorAction SilentlyContinue | Stop-Process -Force   # relaunched with the rest at the end
    'patched ' + (Get-DiscordApp).Name
}

# ---------- Prism Launcher (nightly) ----------
Step 'Prism Launcher (nightly)' {
    if ($DL.VCRedist) {   # Prism's MSVC build needs the VC++ runtime
        $p = Start-Process (Wait-Download $DL.VCRedist) -ArgumentList '/install', '/quiet', '/norestart' -Wait -PassThru
        Say "VC++ runtime installer exit $($p.ExitCode)"
    }
    $zip = Wait-Download $DL.Prism
    $dest = "$env:LOCALAPPDATA\Programs\PrismLauncher"
    Get-Process prismlauncher -ErrorAction SilentlyContinue | Stop-Process -Force
    New-Item -ItemType Directory -Force $dest | Out-Null
    Add-Type -AssemblyName System.IO.Compression.FileSystem
    $tmp = Join-Path $Work 'prism'
    Remove-Item $tmp -Recurse -Force -ErrorAction SilentlyContinue
    [IO.Compression.ZipFile]::ExtractToDirectory($zip, $tmp)
    $exe = Get-ChildItem $tmp -Recurse -Filter 'prismlauncher.exe' | Select-Object -First 1
    if (-not $exe) { throw 'prismlauncher.exe not in the archive' }
    Copy-Item "$($exe.DirectoryName)\*" $dest -Recurse -Force
    $ws = New-Object -ComObject WScript.Shell
    foreach ($dir in [Environment]::GetFolderPath('Desktop'), [Environment]::GetFolderPath('Programs')) {
        $lnk = $ws.CreateShortcut("$dir\Prism Launcher.lnk")
        $lnk.TargetPath = "$dest\prismlauncher.exe"; $lnk.WorkingDirectory = $dest; $lnk.Save()
    }
    "$($S.PrismVer) -> $dest"
}

# ---------- 1Password (nightly) ----------
Step '1Password desktop (nightly)' {
    $msi = Wait-Download $DL.OnePassword
    $p = Start-Process msiexec.exe -ArgumentList '/i', "`"$msi`"", '/qn', '/norestart' -Wait -PassThru
    if ($p.ExitCode -notin 0, 3010, 1641) { throw "msiexec exit $($p.ExitCode)" }
    $S.OnePassword = @("$env:ProgramFiles\1Password\app\8\1Password.exe", "$env:LOCALAPPDATA\1Password\app\8\1Password.exe") |
        Where-Object { Test-Path $_ } | Select-Object -First 1
    if (-not $S.OnePassword) {
        $S.OnePassword = Get-ChildItem "$env:ProgramFiles\1Password", "${env:ProgramFiles(x86)}\1Password", "$env:LOCALAPPDATA\1Password" `
            -Recurse -Filter '1Password.exe' -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName }
    if (-not $S.OnePassword) { throw '1Password.exe not found after install' }
    Split-Path -Leaf $S.OnePasswordUrl
}

# ---------- Steam install (only if the club has none) ----------
Step 'Steam: install' {
    if ($S.Steam) { return "already installed: $($S.Steam)" }
    $exe = Wait-Download $DL.Steam
    Start-Process $exe -ArgumentList '/S' -Wait
    $S.Steam = Find-Steam
    if (-not $S.Steam) { throw 'steam.exe not found after install' }
    $S.Steam
}

# ---------- default browser ----------
Step 'Chrome as default browser' {
    if (-not $S.Chrome) { throw 'no Chrome' }
    $uc = 'HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice'
    $cur = (Get-ItemProperty $uc -ErrorAction SilentlyContinue).ProgId
    if ($cur -eq 'ChromeHTML') { return 'already default' }
    # Windows 10/11 only lets the user set it (hash-protected + UCPD driver). Open Chrome's page in Settings at the
    # very end: one click on "Set default".
    $S.OpenDefaultApps = if ($S.Chrome -like "$env:LOCALAPPDATA*") { 'registeredAppUser' } else { 'registeredAppMachine' }
    "currently '$cur' - Settings will open at the end: click 'Set default'"
}

# ---------- launch everything for sign-in ----------
function Start-App([string]$Path, [string]$Arguments = '') {
    # Launch through Explorer so the app runs as the normal (non-elevated) user, not as this admin shell.
    if (-not (Get-Process explorer -ErrorAction SilentlyContinue)) {
        if ($Arguments) { Start-Process $Path -ArgumentList $Arguments } else { Start-Process $Path }; return }
    $lnkPath = Join-Path $Work ('run-' + [IO.Path]::GetFileNameWithoutExtension($Path) + '.lnk')
    $lnk = (New-Object -ComObject WScript.Shell).CreateShortcut($lnkPath)
    $lnk.TargetPath = $Path; $lnk.Arguments = $Arguments; $lnk.WorkingDirectory = Split-Path $Path; $lnk.Save()
    Start-Process explorer.exe -ArgumentList "`"$lnkPath`""
}
Step 'Launch apps' {
    Get-Process chrome, Discord -ErrorAction SilentlyContinue | Stop-Process -Force   # restart so policies + English apply
    Start-Sleep 1
    $started = @()
    if ($S.Chrome) { Start-App $S.Chrome; $started += 'Chrome' }
    if (Test-Path $discordUpdate) { Start-App $discordUpdate '--processStart Discord.exe'; $started += 'Discord' }
    $pl = "$env:LOCALAPPDATA\Programs\PrismLauncher\prismlauncher.exe"; if (Test-Path $pl) { Start-App $pl; $started += 'Prism' }
    if ($S.OnePassword) { Start-App $S.OnePassword; $started += '1Password' }
    if ($S.Steam) { Start-App $S.Steam '-language english'; $started += 'Steam' }
    $started -join ', '
}

# last: may download a language pack for minutes, and restarts Explorer
Step 'Windows display language -> English (best effort)' {
    $hasEn = Test-Path "$env:windir\System32\en-US\shell32.dll.mui"
    if (-not $hasEn -and (Get-Command Install-Language -ErrorAction SilentlyContinue)) {
        Say 'English language pack missing - installing from Windows Update (can take a few minutes)...'
        $job = Start-Job { Install-Language en-US -ErrorAction Stop | Out-Null }
        if (Wait-Job $job -Timeout 600) { Receive-Job $job -ErrorAction SilentlyContinue | Out-Null }
        else { Stop-Job $job; Say 'language pack install timed out' }
        $hasEn = Test-Path "$env:windir\System32\en-US\shell32.dll.mui"
    }
    if (-not $hasEn) { throw 'no English language pack on this PC (and it could not be installed)' }
    Set-WinUILanguageOverride -Language en-US
    # The override normally applies at next sign-in; write the live value too and restart Explorer so new windows pick it up.
    Set-ItemProperty 'HKCU:\Control Panel\Desktop' -Name PreferredUILanguages -Type MultiString -Value @('en-US')
    if (Get-Process explorer -ErrorAction SilentlyContinue) {
        Stop-Process -Name explorer -Force
        Start-Sleep 2
        if (-not (Get-Process explorer -ErrorAction SilentlyContinue)) { Start-Process explorer.exe }
    }
    'set; Explorer restarted (full switch needs a sign-in, which this script never does)'
}

if ($S.OpenDefaultApps) { Start-Process "ms-settings:defaultapps?$($S.OpenDefaultApps)=Google%20Chrome" }

Write-Host "`n================ SUMMARY ================" -ForegroundColor Cyan
foreach ($k in $Results.Keys) {
    $v = $Results[$k]
    Write-Host ('{0,-62} {1}' -f $k, $v) -ForegroundColor $(if ($v -like 'OK*') { 'Green' } else { 'Red' })
}
Write-Host "Log: $Work\setup.log"
try { Stop-Transcript | Out-Null } catch {}
if (-not $env:CLUB_SETUP_NONINTERACTIVE) { Read-Host 'Done. Press Enter to close' }
}