# Pc inrichten - Bouwbureau Nederland (one-liner versie, 3 december 2026) # Start in Windows PowerShell (liefst als Administrator): # irm pc.bbnld.nl | iex # # Wat dit doet: # 1. Vraagt een korte naam voor deze pc (bijv. "martijn-mtb"). # 2. Regelt een werkend SSH-account (bij Microsoft 365 / Entra ID / domein / niet-admin # maakt hij automatisch het lokale hulpaccount bbn-agent aan, verborgen van het inlogscherm). # 3. Installeert Tailscale (officieel gesigneerde MSI) en koppelt deze pc aan het netwerk. # 4. Installeert OpenSSH-server (officieel door Microsoft gesigneerde MSI of Windows-onderdeel), # zet alleen de openbare sleutel van Bouwbureau Nederland aan (geen wachtwoorden) en opent # poort 22 in de firewall uitsluitend voor Tailscale (100.64.0.0/10). # 5. Zet de agent-hulpjes en controle-/verwijderscripts in C:\BBN-Support. # # Alles weer volledig weghalen (na een demo of proef): # irm pc.bbnld.nl/tunnel | iex # # Optionele omgevingsvariabelen (vooraf te zetten in PowerShell): # $env:BBN_NAAM = "martijn-mtb" # naam zonder vraag # $env:TS_AUTHKEY = "tskey-auth-..." # Tailscale koppelen zonder browser-login # $env:BBN_CLAUDE = "1" # Claude Code ook op deze pc installeren # $env:BBN_WAKKER = "1" # slaapstand aan stroom uitzetten (vaste pc) # $env:BBN_STIL = "1" # geen vragen of Enter aan het eind $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' try { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 } catch { } try { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor 3072 } catch { } $BaseUrl = 'https://pc.bbnld.nl' function Test-IsAdminInit { $id = [Security.Principal.WindowsIdentity]::GetCurrent() (New-Object Security.Principal.WindowsPrincipal $id).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) } # --- Zelf-verhoging als niet als Administrator gestart ------------------------------------------ if (-not (Test-IsAdminInit)) { Write-Host '' Write-Host ' Beheerdersrechten nodig. Er opent zo een Windows-venster: klik op Ja.' -ForegroundColor Yellow $tmp = Join-Path $env:TEMP 'bbn-pc-inrichten.ps1' Invoke-WebRequest -Uri "$BaseUrl/pc-inrichten.ps1" -OutFile $tmp -UseBasicParsing -TimeoutSec 60 try { Unblock-File -Path $tmp -ErrorAction SilentlyContinue } catch { } try { Start-Process powershell.exe -Verb RunAs -ArgumentList @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', "`"$tmp`"") Write-Host ' De installatie loopt verder in het beheerdersvenster. Dit venster mag dicht.' -ForegroundColor Green Start-Sleep -Seconds 3 } catch { Write-Host " Beheerdersrechten geweigerd of mislukt: $($_.Exception.Message)" -ForegroundColor Red Write-Host ' Tip: klik met de rechtermuisknop op PowerShell en kies "Als administrator uitvoeren".' -ForegroundColor Yellow if ($env:BBN_STIL -ne '1') { Read-Host ' Druk op Enter om te sluiten' | Out-Null } } return } # --- Voorbereiden en hulpbestanden ophalen ------------------------------------------------------ $Host.UI.RawUI.WindowTitle = 'Pc inrichten - Bouwbureau Nederland' $stil = ($env:BBN_STIL -eq '1') $pakketMap = 'C:\BBN-Support\pc-inrichten' $agentMap = 'C:\BBN-Support\agent' New-Item -ItemType Directory -Force $pakketMap, (Join-Path $pakketMap 'ssh'), (Join-Path $agentMap 'pc-hulp'), (Join-Path $agentMap 'tmp'), (Join-Path $agentMap 'doorgeef'), (Join-Path $agentMap 'browser') | Out-Null $log = Join-Path $pakketMap ("setup-{0:yyyyMMdd-HHmm}.log" -f (Get-Date)) try { Start-Transcript -Path $log -Append | Out-Null } catch { } try { Clear-Host Write-Host '=====================================================================' -ForegroundColor Cyan Write-Host ' Pc inrichten voor Bouwbureau Nederland' -ForegroundColor Cyan Write-Host '=====================================================================' -ForegroundColor Cyan Write-Host '' Write-Host ' Dit zet veilig een Tailscale + OpenSSH-verbinding klaar voor onze' Write-Host ' Machinekamer-agent (alleen met sleutel, geen wachtwoorden).' Write-Host ' Koppeling later weer sluiten kan altijd met: irm pc.bbnld.nl/tunnel | iex' Write-Host '' Write-Host ' Hulpbestanden ophalen van pc.bbnld.nl...' -ForegroundColor DarkGray $bestanden = @( @{ url = "$BaseUrl/bestanden/lib.ps1"; doel = Join-Path $pakketMap 'lib.ps1' }, @{ url = "$BaseUrl/controle.ps1"; doel = Join-Path $pakketMap 'controle.ps1' }, @{ url = "$BaseUrl/verwijder.ps1"; doel = Join-Path $pakketMap 'verwijder.ps1' }, @{ url = "$BaseUrl/bestanden/kit.json"; doel = Join-Path $pakketMap 'kit.json' }, @{ url = "$BaseUrl/bestanden/servers.pub"; doel = Join-Path $pakketMap 'ssh\servers.pub' }, @{ url = "$BaseUrl/bestanden/sshd_config"; doel = Join-Path $pakketMap 'ssh\sshd_config' }, @{ url = "$BaseUrl/bestanden/CLAUDE-pc.md"; doel = Join-Path $pakketMap 'CLAUDE-pc.md' }, @{ url = "$BaseUrl/bestanden/scherm.ps1"; doel = Join-Path $agentMap 'pc-hulp\scherm.ps1' }, @{ url = "$BaseUrl/bestanden/versie.txt"; doel = Join-Path $agentMap 'pc-hulp\versie.txt' } ) foreach ($b in $bestanden) { Invoke-WebRequest -Uri $b.url -OutFile $b.doel -UseBasicParsing -TimeoutSec 60 try { Unblock-File -Path $b.doel -ErrorAction SilentlyContinue } catch { } } . (Join-Path $pakketMap 'lib.ps1') $kitInfo = Lees-Kit $stand = Lees-Json $script:StandPad Zet-Prop $stand 'laatsteInstallatie' (Get-Date).ToString('s') Zet-Prop $stand 'kitVersie' $kitInfo.versie # --- 1. Naam kiezen ------------------------------------------------------------------------- Kop 'Naam voor deze pc' $oud = Lees-Json $script:PcJson $voorstel = if ($env:BBN_NAAM) { $env:BBN_NAAM } elseif ($oud.naam) { [string]$oud.naam } else { $env:COMPUTERNAME } $gekozen = $voorstel if (-not $stil) { Write-Host ' Onder deze naam roep je deze pc straks aan in de Machinekamer (bijv. martijn-mtb).' $in = Read-Host " Naam [Enter = $voorstel]" if ($in -and $in.Trim()) { $gekozen = $in.Trim() } } $hostnaam = Maak-Hostnaam $gekozen if (-not $hostnaam) { throw "Van de naam '$gekozen' blijft niets over; gebruik letters of cijfers." } Goed "Naam: $gekozen (in Tailscale: $hostnaam)" # --- 2. Gebruiker en SSH-account bepalen ---------------------------------------------------- Kop 'Windows-gebruiker en SSH-toegang' $gebr = Get-Gebruiker $isEntra = ($gebr.Naam -match '^AzureAD\\') $isDomein = ($gebr.Domein -and ($gebr.Domein.ToUpper() -ne $env:COMPUTERNAME.ToUpper()) -and (-not $isEntra)) $heeftSpatie = ($gebr.Kort -match '[^a-zA-Z0-9._-]') $isAdmin = if (-not $isEntra) { Is-Beheerder $gebr.Kort } else { $false } $nodigLokaal = ($isEntra -or $isDomein -or $heeftSpatie -or (-not $isAdmin) -or ($env:BBN_LOKAAL_ACCOUNT -eq '1')) Info "Aangemelde gebruiker: $($gebr.Naam)" $sshNaam = $gebr.Kort.ToLower() if ($nodigLokaal) { $reden = if ($isEntra) { 'Microsoft 365 / Entra ID-account' } elseif ($isDomein) { "domeinaccount ($($gebr.Domein))" } elseif ($heeftSpatie) { 'spatie of teken in gebruikersnaam' } elseif (-not $isAdmin) { 'gebruiker is geen lokale beheerder' } else { 'aangevraagd via BBN_LOKAAL_ACCOUNT' } Info "Reden voor lokaal hulpaccount '$($script:AgentUser)': $reden" $adminGroep = Get-AdminGroepNaam $bestaat = $false try { $bestaat = [bool](Get-LocalUser -Name $script:AgentUser -ErrorAction SilentlyContinue) } catch { $bestaat = ((& net.exe user $script:AgentUser 2>$null) -and $LASTEXITCODE -eq 0) } if (-not $bestaat) { $ww = Nieuw-Wachtwoord 28 $sec = ConvertTo-SecureString $ww -AsPlainText -Force try { New-LocalUser -Name $script:AgentUser -Password $sec -FullName 'BBNL Agent (tijdelijk SSH-account)' -Description 'Aangemaakt door pc.bbnld.nl; wordt verwijderd door verwijder.ps1' -PasswordNeverExpires -AccountNeverExpires | Out-Null } catch { $r = Start-Native 'net.exe' @('user', $script:AgentUser, $ww, '/add', '/y', '/comment:BBNL Agent') if ($r.Code -ne 0) { throw "Kon lokaal account $($script:AgentUser) niet aanmaken: $($r.Uitvoer)" } } Zet-Prop $stand 'lokaalAccountDoorOns' $script:AgentUser Goed "Lokaal beheerdersaccount '$($script:AgentUser)' aangemaakt (alleen voor SSH-sleutel)" } else { try { Enable-LocalUser -Name $script:AgentUser -ErrorAction SilentlyContinue } catch { } Goed "Lokaal account '$($script:AgentUser)' bestond al en is actief" } if (-not (Is-Beheerder $script:AgentUser)) { try { Add-LocalGroupMember -Group $adminGroep -Member $script:AgentUser -ErrorAction Stop } catch { Start-Native 'net.exe' @('localgroup', $adminGroep, $script:AgentUser, '/add') | Out-Null } } # Verberg hulpaccount op het grafische Windows-inlogscherm $hideKey = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList' if (-not (Test-Path $hideKey)) { New-Item -Path $hideKey -Force | Out-Null } New-ItemProperty -Path $hideKey -Name $script:AgentUser -Value 0 -PropertyType DWord -Force | Out-Null $sshNaam = $script:AgentUser Goed "SSH loopt via '$sshNaam' (verborgen op het inlogscherm; schermacties lopen als $($gebr.Naam))" } else { Goed "SSH loopt direct via lokale beheerder '$sshNaam'" } # --- 3. Tailscale installeren en verbinden -------------------------------------------------- Kop 'Tailscale (beveiligde tunnel naar de Machinekamer)' if (-not (Test-Path $script:TsExe)) { $arch = if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') { 'arm64' } else { 'amd64' } $msi = Join-Path $env:TEMP "tailscale-setup-$arch.msi" Download-Bestand "https://pkgs.tailscale.com/stable/tailscale-setup-latest-$arch.msi" $msi $sig = Get-AuthenticodeSignature $msi if ($sig.Status -ne 'Valid' -or $sig.SignerCertificate.Subject -notmatch 'Tailscale') { throw "Handtekening van het Tailscale-installatiebestand klopt niet ($($sig.Status))." } Info 'Tailscale installeren (circa 20 seconden)...' $p = Start-Process msiexec.exe -ArgumentList @('/i', "`"$msi`"", '/qn', '/norestart', 'TS_UNATTENDEDMODE=always', 'TS_NOLAUNCH=true', '/l*v', "`"$(Join-Path $pakketMap 'tailscale-msi.log')`"") -Wait -PassThru if (-not (Test-Path $script:TsExe)) { throw "Tailscale is niet geinstalleerd (msiexec gaf $($p.ExitCode); zie tailscale-msi.log)." } Zet-Prop $stand 'tailscaleDoorOns' $true Goed 'Tailscale geinstalleerd' } else { Goed 'Tailscale stond er al' } $svcTs = Get-Service Tailscale -ErrorAction SilentlyContinue if ($svcTs) { if ($svcTs.StartType -ne 'Automatic') { Set-Service Tailscale -StartupType Automatic } if ($svcTs.Status -ne 'Running') { Start-Service Tailscale; Start-Sleep -Seconds 3 } } $ts = $null for ($i = 0; $i -lt 25 -and -not $ts; $i++) { $ts = Ts-Stand if (-not $ts) { Start-Sleep -Seconds 2 } } if (-not $ts) { throw 'Tailscale antwoordt niet (dienst Tailscale).' } if ($ts.BackendState -eq 'Running') { $netNaam = if ($ts.CurrentTailnet -and $ts.CurrentTailnet.Name) { [string]$ts.CurrentTailnet.Name } else { 'onbekend' } Info "Tailscale is al verbonden met netwerk: $netNaam" $r = Start-Native $script:TsExe @('set', "--hostname=$hostnaam", '--unattended=true') if ($r.Code -ne 0) { Let "Tailscale-naam zetten gaf: $($r.Uitvoer)" } else { Goed "Tailscale verbonden (naam: $hostnaam, onbeheerd aan)" } } else { $upArgs = @('up', '--reset', '--unattended', "--hostname=$hostnaam") if ($env:TS_AUTHKEY) { $upArgs += "--auth-key=$($env:TS_AUTHKEY)" Info 'Aanmelden met opgegeven TS_AUTHKEY...' } $uit = Join-Path $env:TEMP 'bbn-ts-uit.txt' $err = Join-Path $env:TEMP 'bbn-ts-err.txt' Remove-Item $uit, $err -ErrorAction SilentlyContinue $tsProc = Start-Process -FilePath $script:TsExe -ArgumentList $upArgs -RedirectStandardOutput $uit -RedirectStandardError $err -WindowStyle Hidden -PassThru $geopend = $false $eind = (Get-Date).AddMinutes(15) while ((Get-Date) -lt $eind -and -not (Ts-Ip)) { Start-Sleep -Seconds 2 if (-not $geopend) { $tekst = '' foreach ($f in @($uit, $err)) { if (Test-Path $f) { $tekst += (Get-Content $f -Raw -ErrorAction SilentlyContinue) } } if ($tekst -match '(https://login\.tailscale\.com/\S+)') { $url = $Matches[1] $geopend = $true Write-Host '' Write-Host ' ===================================================================' -ForegroundColor Yellow Write-Host ' KOPPEL TAILSCALE (log in met het account van Max):' -ForegroundColor Yellow Write-Host '' Write-Host " $url" -ForegroundColor White Write-Host '' Write-Host ' Tip bij een klant: open deze link op je eigen telefoon of laptop,' -ForegroundColor Yellow Write-Host ' dan hoef je je wachtwoord niet op deze pc in te typen.' -ForegroundColor Yellow Write-Host ' ===================================================================' -ForegroundColor Yellow Write-Host '' try { Set-Clipboard -Value $url } catch { } if (-not $stil) { try { Start-Process $url } catch { } } } if ($tsProc.HasExited -and $tsProc.ExitCode -ne 0 -and -not $geopend) { throw "tailscale up mislukte: $tekst" } } } if (-not (Ts-Ip)) { throw 'Tailscale is niet verbonden binnen 15 minuten. Start het commando opnieuw.' } Goed "Tailscale verbonden als $hostnaam" } $ts = Ts-Stand $tsIp = Ts-Ip $tsNaam = $hostnaam if ($ts.Self -and $ts.Self.DNSName) { $tsNaam = ($ts.Self.DNSName -split '\.')[0] } if ($tsNaam -ne $hostnaam) { Let "De naam $hostnaam bestond al; deze pc heet in Tailscale nu: $tsNaam" } Goed "Tailscale-adres: $tsIp ($tsNaam)" # --- 4. OpenSSH-server installeren ---------------------------------------------------------- Kop 'OpenSSH-server' if (Get-Service sshd -ErrorAction SilentlyContinue) { Goed "OpenSSH-server stond er al ($(Get-SshdExe))" if ($null -eq $stand.PSObject.Properties['sshdDoorOns']) { Zet-Prop $stand 'sshdDoorOns' $false } } else { $gelukt = $false if ($env:PROCESSOR_ARCHITECTURE -eq 'AMD64') { try { $msi = Join-Path $env:TEMP 'OpenSSH-Win64-v10.4.0.0.msi' Download-Bestand "$BaseUrl/bestanden/OpenSSH-Win64-v10.4.0.0.msi" $msi $sig = Get-AuthenticodeSignature $msi if ($sig.Status -eq 'Valid' -and $sig.SignerCertificate.Subject -match 'Microsoft') { Info 'OpenSSH (Microsoft MSI) installeren...' $p = Start-Process msiexec.exe -ArgumentList @('/i', "`"$msi`"", '/qn', '/norestart', 'ADDLOCAL=Server', '/l*v', "`"$(Join-Path $pakketMap 'openssh-msi.log')`"") -Wait -PassThru if (-not (Get-Service sshd -ErrorAction SilentlyContinue)) { $p = Start-Process msiexec.exe -ArgumentList @('/i', "`"$msi`"", '/qn', '/norestart', '/l*v', "`"$(Join-Path $pakketMap 'openssh-msi-2.log')`"") -Wait -PassThru } $gelukt = [bool](Get-Service sshd -ErrorAction SilentlyContinue) if ($gelukt) { Zet-Prop $stand 'sshdBron' 'msi' } else { Info "MSI gaf code $($p.ExitCode); ik val terug op Windows-onderdelen." } } else { Info "Handtekening van OpenSSH MSI klopt niet ($($sig.Status)); ik gebruik Windows-onderdelen." } } catch { Info "MSI-route mislukte ($($_.Exception.Message)); ik gebruik Windows-onderdelen." } } if (-not $gelukt) { Info 'OpenSSH-server installeren via Windows-onderdelen (kan 1-3 minuten duren)...' Add-WindowsCapability -Online -Name 'OpenSSH.Server~~~~0.0.1.0' | Out-Null if (-not (Get-Service sshd -ErrorAction SilentlyContinue)) { throw 'OpenSSH-server kon niet worden geinstalleerd.' } Zet-Prop $stand 'sshdBron' 'windows' } Zet-Prop $stand 'sshdDoorOns' $true Goed "OpenSSH-server geinstalleerd ($(Get-SshdExe))" } $sshdExe = Get-SshdExe if ((Get-Service sshd).StartType -eq 'Disabled') { Set-Service sshd -StartupType Manual } if (-not (Test-Path (Join-Path $script:SshData 'ssh_host_ed25519_key'))) { try { Start-Service sshd; Start-Sleep -Seconds 3; Stop-Service sshd } catch { } } if (-not (Test-Path (Join-Path $script:SshData 'ssh_host_ed25519_key'))) { Start-Native (Join-Path (Split-Path $sshdExe) 'ssh-keygen.exe') @('-A') | Out-Null } # --- 5. Sleutels en veilige sshd_config ----------------------------------------------------- Kop 'SSH-sleutel en instellingen' $bestaand = @() if (Test-Path $script:SleutelPad) { $bestaand = @(Get-Content $script:SleutelPad | Where-Object { $_.Trim() }) } $erbij = 0 foreach ($pub in (Get-Content (Join-Path $pakketMap 'ssh\servers.pub') | Where-Object { $_ -match '^ssh-(ed25519|rsa) ' })) { $delen = $pub.Trim() -split '\s+' if (-not ($bestaand | Where-Object { $_ -like "*$($delen[1])*" })) { $bestaand += "from=`"$($kitInfo.tailnetBereik)`",no-agent-forwarding,no-X11-forwarding $($pub.Trim())" $erbij++ } } if (-not $bestaand.Count) { throw 'Geen geldige openbare sleutel gevonden.' } New-Item -ItemType Directory -Force $script:SshData | Out-Null [IO.File]::WriteAllText($script:SleutelPad, (($bestaand -join "`n") + "`n"), (New-Object Text.ASCIIEncoding)) Zet-Rechten $script:SleutelPad @(@($script:SidSystem, 'FullControl'), @($script:SidAdmins, 'FullControl')) Goed "Sleutels opgeslagen ($($bestaand.Count) totaal, $erbij nieuw, alleen vanaf $($kitInfo.tailnetBereik))" $cfg = Join-Path $script:SshData 'sshd_config' $backup = Get-ChildItem $script:SshData -Filter 'sshd_config.voor-bbn-*' -ErrorAction SilentlyContinue | Select-Object -First 1 if ((Test-Path $cfg) -and -not $backup) { $bnaam = 'sshd_config.voor-bbn-{0:yyyyMMdd-HHmm}' -f (Get-Date) Copy-Item $cfg (Join-Path $script:SshData $bnaam) Zet-Prop $stand 'sshdConfigBackup' $bnaam Info "Vorige sshd_config bewaard als $bnaam" } $nieuw = Get-Content (Join-Path $pakketMap 'ssh\sshd_config') -Raw $tmpCfg = "$cfg.nieuw" [IO.File]::WriteAllText($tmpCfg, $nieuw.Replace("`r`n", "`n").Replace("`n", "`r`n"), (New-Object Text.ASCIIEncoding)) $test = Start-Native $sshdExe @('-t', '-f', $tmpCfg) if ($test.Code -ne 0) { Remove-Item $tmpCfg -Force -ErrorAction SilentlyContinue throw "sshd keurt de instellingen af: $($test.Uitvoer)" } Move-Item $tmpCfg $cfg -Force Goed 'sshd_config actief (alleen met sleutel, geen wachtwoorden)' $regSsh = 'HKLM:\SOFTWARE\OpenSSH' $oudShell = (Get-ItemProperty -Path $regSsh -Name DefaultShell -ErrorAction SilentlyContinue).DefaultShell if ($oudShell) { Zet-Prop $stand 'defaultShellVoorBbn' $oudShell Remove-ItemProperty -Path $regSsh -Name DefaultShell Info "DefaultShell ($oudShell) teruggezet naar cmd.exe (vereist voor werkpc)" } # --- 6. Firewall ---------------------------------------------------------------------------- Kop 'Firewall (poort 22 alleen vanaf Tailscale)' $uitgezet = @() if ($stand.PSObject.Properties['firewallUitgezet']) { $uitgezet = @($stand.firewallUitgezet) } $poortRegels = Get-NetFirewallPortFilter -Protocol TCP -ErrorAction SilentlyContinue | Where-Object { $_.LocalPort -contains '22' } | Get-NetFirewallRule -ErrorAction SilentlyContinue $appRegels = Get-NetFirewallApplicationFilter -ErrorAction SilentlyContinue | Where-Object { $_.Program -like '*sshd.exe' } | Get-NetFirewallRule -ErrorAction SilentlyContinue foreach ($r in @($poortRegels) + @($appRegels)) { if (-not $r -or $r.Name -eq $script:RegelNaam) { continue } if ($r.Direction -eq 'Inbound' -and $r.Action -eq 'Allow' -and $r.Enabled -eq 'True') { $adres = ($r | Get-NetFirewallAddressFilter -ErrorAction SilentlyContinue).RemoteAddress if (@($adres) -contains 'Any') { Disable-NetFirewallRule -Name $r.Name -ErrorAction SilentlyContinue if ($uitgezet -notcontains $r.Name) { $uitgezet += $r.Name } Info "Te brede regel uitgezet: $($r.DisplayName)" } } } Zet-Prop $stand 'firewallUitgezet' $uitgezet Get-NetFirewallRule -Name $script:RegelNaam -ErrorAction SilentlyContinue | Remove-NetFirewallRule -ErrorAction SilentlyContinue New-NetFirewallRule -Name $script:RegelNaam -DisplayName 'BBN werkpc ssh (alleen Tailscale)' ` -Description 'Bouwbureau Nederland: SSH alleen over Tailscale. Sluiten: irm pc.bbnld.nl/tunnel | iex' ` -Direction Inbound -Protocol TCP -LocalPort 22 -RemoteAddress $kitInfo.tailnetBereik -Action Allow -Profile Any | Out-Null Goed "Firewallregel '$($script:RegelNaam)': poort 22 alleen vanaf $($kitInfo.tailnetBereik)" # --- 7. SSH-dienst starten ------------------------------------------------------------------ Kop 'SSH-server starten' Set-Service sshd -StartupType Automatic & sc.exe failure sshd reset= 86400 actions= restart/60000/restart/60000/restart/60000 | Out-Null Restart-Service sshd -Force Start-Sleep -Seconds 2 if ((Get-Service sshd).Status -ne 'Running') { throw 'sshd start niet; controleer Windows Event Viewer (OpenSSH).' } Goed 'OpenSSH-server draait en start vanzelf met Windows' # --- 8. Werkmap, rechten en metadata -------------------------------------------------------- Kop 'Werkmap C:\BBN-Support' & icacls.exe $agentMap /grant '*S-1-5-32-545:(OI)(CI)M' /T /Q | Out-Null Get-ChildItem $script:Werk -Recurse -File -ErrorAction SilentlyContinue | Unblock-File -ErrorAction SilentlyContinue $claudeMd = Join-Path $script:Werk 'CLAUDE.md' $merk = 'pc-inrichten (algemene versie)' if (-not (Test-Path $claudeMd) -or (Select-String -Path $claudeMd -Pattern ([regex]::Escape($merk)) -Quiet)) { $tekst = (Get-Content (Join-Path $pakketMap 'CLAUDE-pc.md') -Raw).Replace('__NAAM__', $gekozen).Replace('__HOSTNAAM__', $tsNaam).Replace('__COMPUTER__', $env:COMPUTERNAME).Replace('__GEBRUIKER__', $gebr.Naam).Replace('__POORT__', "$($kitInfo.browserPoort)") [IO.File]::WriteAllText($claudeMd, $tekst, (New-Object Text.UTF8Encoding $false)) } if ($env:BBN_WAKKER -eq '1') { & powercfg.exe /change standby-timeout-ac 0 | Out-Null & powercfg.exe /change hibernate-timeout-ac 0 | Out-Null Zet-Prop $stand 'slaapUitgezet' $true Goed 'Slaapstand aan de stroom uitgezet (BBN_WAKKER=1)' } # Optioneel Claude Code op deze pc (standaard uit voor snelle klant-demo via Machinekamer) $wilClaude = ($env:BBN_CLAUDE -eq '1') $claudeAccount = '' if (-not $wilClaude -and -not $stil -and $env:BBN_CLAUDE -ne '0') { Write-Host '' $cAntw = Read-Host ' Ook Claude Code lokaal op deze pc installeren? [Enter = overslaan (snel voor demo), typ J voor ja]' if ($cAntw -match '^[jJ]') { $wilClaude = $true } } if ($wilClaude) { Kop 'Claude Code (optioneel)' try { if (-not (Claude-Exe)) { Info 'Claude Code installeren...' powershell.exe -NoProfile -ExecutionPolicy Bypass -Command 'irm https://claude.ai/install.ps1 | iex' } if (Claude-Exe) { Goed "Claude Code staat er ($((& (Claude-Exe) --version) -join ' '))" $claudeAccount = Claude-Account if (-not $claudeAccount -and -not $stil) { $oudEap = $ErrorActionPreference; $ErrorActionPreference = 'Continue' try { & (Claude-Exe) auth login --claudeai } finally { $ErrorActionPreference = $oudEap } $claudeAccount = Claude-Account } Configureer-Claude } else { Let 'Claude Code niet gevonden na installatie; SSH-besturing werkt gewoon zonder.' } } catch { Let "Claude Code overgeslagen: $($_.Exception.Message)" } } Schrijf-Json $script:PcJson ([pscustomobject]@{ naam = $gekozen hostnaam = $tsNaam tailscaleIp = $tsIp computer = $env:COMPUTERNAME gebruiker = $gebr.Naam sshGebruiker = $sshNaam claudeAccount = $claudeAccount browserPoort = $kitInfo.browserPoort kitVersie = $kitInfo.versie ingericht = (Get-Date).ToString('s') }) Schrijf-Json $script:StandPad $stand Goed 'C:\BBN-Support\pc.json en stand.json opgeslagen' # --- 9. Controle en koppelregel ------------------------------------------------------------- & (Join-Path $pakketMap 'controle.ps1') -AlsDeel $regel = "koppel pc $tsNaam gebruiker $sshNaam" [IO.File]::WriteAllText((Join-Path $script:Werk 'koppelregel.txt'), $regel, (New-Object Text.ASCIIEncoding)) try { Set-Clipboard -Value $regel } catch { } Write-Host '' Write-Host '=====================================================================' -ForegroundColor Green Write-Host ' KLAAR OP DEZE PC!' -ForegroundColor Green Write-Host '' -ForegroundColor Green Write-Host ' Zeg nu tegen je chatagent in de Machinekamer:' -ForegroundColor Green Write-Host '' Write-Host " $regel" -ForegroundColor White Write-Host '' Write-Host ' (Deze regel staat ook op het klembord en in C:\BBN-Support\koppelregel.txt)' -ForegroundColor DarkGray Write-Host ' Koppeling na de demo weer sluiten? Draai: irm pc.bbnld.nl/tunnel | iex' -ForegroundColor DarkGray Write-Host '=====================================================================' -ForegroundColor Green } catch { Write-Host '' Write-Host "FOUT: $($_.Exception.Message)" -ForegroundColor Red Write-Host $_.ScriptStackTrace -ForegroundColor DarkGray Write-Host "Logboek: $log" Write-Host 'Je mag het commando gewoon opnieuw draaien; wat al klaar is, slaat hij over.' } finally { try { Stop-Transcript | Out-Null } catch { } } if (-not $stil) { Write-Host '' Read-Host 'Druk op Enter om dit venster te sluiten' | Out-Null }