# 2>NUL & @CLS & PUSHD "%~dp0" & "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -noLogo -noProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText('%~f0')|iex" & POPD & EXIT /B # Check and install dependencies if needed Write-Host "Controleer dependencies..." -ForegroundColor Yellow # Check if winget is available try { $wingetVersion = winget --version 2>$null if ($wingetVersion) { Write-Host "winget is beschikbaar: $wingetVersion" -ForegroundColor Green } else { throw "winget niet gevonden" } } catch { Write-Host "winget niet gevonden. Probeer te installeren..." -ForegroundColor Red # Try to install winget from Microsoft Store try { Write-Host "Installeer winget via Microsoft Store..." -ForegroundColor Yellow Start-Process "ms-windows-store://pdp/?ProductId=9NBLGGH4NNS1" -Wait Write-Host "Controleer of winget nu beschikbaar is..." -ForegroundColor Yellow # Wait a bit and check again Start-Sleep -Seconds 5 $wingetVersion = winget --version 2>$null if ($wingetVersion) { Write-Host "winget succesvol geïnstalleerd: $wingetVersion" -ForegroundColor Green } else { throw "winget installatie mislukt" } } catch { Write-Host "Automatische winget installatie mislukt. Probeer handmatig:" -ForegroundColor Red Write-Host "1. Open Microsoft Store" -ForegroundColor White Write-Host "2. Zoek naar 'App Installer'" -ForegroundColor White Write-Host "3. Installeer de App Installer" -ForegroundColor White Write-Host "4. Herstart PowerShell en voer dit script opnieuw uit" -ForegroundColor White Read-Host "Druk op Enter om af te sluiten" exit 1 } } # Check if running as administrator $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") if (-not $isAdmin) { Write-Host "Dit script moet als Administrator worden uitgevoerd voor machine-wide installaties." -ForegroundColor Red Write-Host "Start PowerShell opnieuw als Administrator en voer dit script opnieuw uit." -ForegroundColor Yellow Read-Host "Druk op Enter om af te sluiten" exit 1 } Write-Host "Alle dependencies zijn beschikbaar. Start met app installaties..." -ForegroundColor Green Write-Host "" # Install apps Write-Host "Bepaal gebruikerstype en laad app lijst..." -ForegroundColor Yellow # Determine user type and load appropriate app list # Get script directory - fallback to current location if MyInvocation is null # When executed via .cmd wrapper, PUSHD sets current directory to script location $scriptDirPath = if ($MyInvocation.MyCommand.Path) { Split-Path -Parent $MyInvocation.MyCommand.Path } else { # Convert PathInfo to string if needed $location = Get-Location if ($location -is [System.IO.DirectoryInfo]) { $location.FullName } else { $location.ToString() } } # Parent directory is the root of the project (one level up from scripts/) $currentDirName = Split-Path -Leaf $scriptDirPath if ($currentDirName -eq "scripts") { $parentDir = Split-Path -Parent $scriptDirPath } else { # If we're already in root, use current directory $parentDir = $scriptDirPath } $medewerkersFile = Join-Path $parentDir "apps\medewerkers.txt" $gastenFile = Join-Path $parentDir "apps\gasten.txt" # Check if user is a medewerker (has specific group membership or file exists) $isMedewerker = $false $isGast = $false # Try to determine user type - you can customize this logic try { # Check if user is in specific AD groups (customize as needed) $userGroups = (Get-ADUser -Identity $env:USERNAME -Properties MemberOf).MemberOf if ($userGroups -match "Medewerkers|Employees|Staff") { $isMedewerker = $true Write-Host "Gebruiker gedetecteerd als medewerker" -ForegroundColor Green } else { $isGast = $true Write-Host "Gebruiker gedetecteerd als gast" -ForegroundColor Yellow } } catch { # Fallback: ask user to choose Write-Host "Kon gebruikerstype niet automatisch bepalen." -ForegroundColor Yellow Write-Host "1. Medewerker" -ForegroundColor White Write-Host "2. Gast" -ForegroundColor White do { $choice = Read-Host "Kies gebruikerstype (1 of 2)" } while ($choice -notin @("1", "2")) if ($choice -eq "1") { $isMedewerker = $true } else { $isGast = $true } } # Load appropriate app list $appsFile = if ($isMedewerker) { $medewerkersFile } else { $gastenFile } $userType = if ($isMedewerker) { "medewerker" } else { "gast" } Write-Host "Gebruikerstype: $userType" -ForegroundColor Cyan Write-Host "App lijst: $appsFile" -ForegroundColor Cyan # Check if app file exists if (-not (Test-Path $appsFile)) { Write-Host "Fout: App lijst niet gevonden: $appsFile" -ForegroundColor Red Read-Host "Druk op Enter om af te sluiten" exit 1 } # Load apps from file try { Write-Host "Laad app lijst..." -ForegroundColor Yellow # Read the content from the file $content = Get-Content $appsFile -Raw $apps = @() # Parse the PowerShell array from the file if ($content -match '\$apps\s*=\s*@\s*\((.*?)\)') { $appsString = $matches[1] $apps = $appsString -split ',' | ForEach-Object { $_.Trim().Trim('"').Trim("'") } | Where-Object { $_ -ne '' } } Write-Host "✓ App lijst geladen: $($apps.Count) apps gevonden" -ForegroundColor Green } catch { Write-Host "Fout bij laden van app lijst: $($_.Exception.Message)" -ForegroundColor Red Read-Host "Druk op Enter om af te sluiten" exit 1 } if ($apps.Count -eq 0) { Write-Host "Geen apps gevonden in de lijst!" -ForegroundColor Red Read-Host "Druk op Enter om af te sluiten" exit 1 } Write-Host "Start installatie van $($apps.Count) apps voor $userType..." -ForegroundColor Green Write-Host "" $totalApps = $apps.Count $currentApp = 0 foreach ($app in $apps) { $currentApp++ Write-Host "[$currentApp/$totalApps] Installeer $app..." -ForegroundColor Cyan try { Start-Process -NoNewWindow -Wait -FilePath "winget" -ArgumentList "install --id $app -e --silent --accept-package-agreements --accept-source-agreements --source winget --scope machine" Write-Host "✓ $app succesvol geïnstalleerd" -ForegroundColor Green } catch { Write-Host "✗ Fout bij installatie van $app" -ForegroundColor Red Write-Host "Foutdetails: $($_.Exception.Message)" -ForegroundColor Red } Write-Host "" } Write-Host "App installatie voltooid!" -ForegroundColor Green Read-Host "Druk op Enter om af te sluiten"