usb-stick fix

This commit is contained in:
rmeijer_huizehetoost committed 2025-10-29 11:23:02 +01:00
1 parent 4cd36332d2
commit 3ce2527fda
4 files changed
+202 -23

No files matched your search

+103 -10
View File
@@ -83,9 +83,22 @@ function Get-SerialNumber {
Write-ColorText "Retrieving laptop serial number..." "Yellow"
# Gebruik de huidige map als uitvoerlocatie
$outputDir = Split-Path -Parent $MyInvocation.ScriptName
if (-not $outputDir) {
$outputDir = Get-Location
$outputDir = if ($MyInvocation.MyCommand.Path) {
Split-Path -Parent $MyInvocation.MyCommand.Path
} elseif ($MyInvocation.ScriptName) {
Split-Path -Parent $MyInvocation.ScriptName
} elseif ($PSCommandPath) {
Split-Path -Parent $PSCommandPath
} elseif ($PSScriptRoot) {
$PSScriptRoot
} else {
# When executed via .cmd wrapper, PUSHD sets current directory
$location = Get-Location
if ($location -is [System.IO.DirectoryInfo]) {
$location.FullName
} else {
$location.ToString()
}
}
Write-ColorText "Uitvoerlocatie: $outputDir" "Cyan"
@@ -253,7 +266,23 @@ function Install-MedewerkersApps {
Write-Host ""
# Lees apps uit medewerkers.txt
$scriptPath = Split-Path -Parent $MyInvocation.ScriptName
$scriptPath = if ($MyInvocation.MyCommand.Path) {
Split-Path -Parent $MyInvocation.MyCommand.Path
} elseif ($MyInvocation.ScriptName) {
Split-Path -Parent $MyInvocation.ScriptName
} elseif ($PSCommandPath) {
Split-Path -Parent $PSCommandPath
} elseif ($PSScriptRoot) {
$PSScriptRoot
} else {
# When executed via .cmd wrapper, PUSHD sets current directory
$location = Get-Location
if ($location -is [System.IO.DirectoryInfo]) {
$location.FullName
} else {
$location.ToString()
}
}
$medewerkersFile = Join-Path $scriptPath "apps\medewerkers.txt"
if (-not (Test-Path $medewerkersFile)) {
@@ -269,7 +298,7 @@ function Install-MedewerkersApps {
# Parse de PowerShell array uit het bestand
if ($content -match '\$apps\s*=\s*@\s*\((.*?)\)') {
$appsString = $matches[1]
$apps = $appsString -split ',' | ForEach-Object { $_.Trim() -replace '"', '' } | Where-Object { $_ -ne '' }
$apps = $appsString -split ',' | ForEach-Object { $_.Trim().Trim('"').Trim("'") } | Where-Object { $_ -ne '' }
}
if ($apps.Count -eq 0) {
@@ -312,7 +341,23 @@ function Install-GastenApps {
Write-Host ""
# Lees apps uit gasten.txt
$scriptPath = Split-Path -Parent $MyInvocation.ScriptName
$scriptPath = if ($MyInvocation.MyCommand.Path) {
Split-Path -Parent $MyInvocation.MyCommand.Path
} elseif ($MyInvocation.ScriptName) {
Split-Path -Parent $MyInvocation.ScriptName
} elseif ($PSCommandPath) {
Split-Path -Parent $PSCommandPath
} elseif ($PSScriptRoot) {
$PSScriptRoot
} else {
# When executed via .cmd wrapper, PUSHD sets current directory
$location = Get-Location
if ($location -is [System.IO.DirectoryInfo]) {
$location.FullName
} else {
$location.ToString()
}
}
$gastenFile = Join-Path $scriptPath "apps\gasten.txt"
if (-not (Test-Path $gastenFile)) {
@@ -328,7 +373,7 @@ function Install-GastenApps {
# Parse de PowerShell array uit het bestand
if ($content -match '\$apps\s*=\s*@\s*\((.*?)\)') {
$appsString = $matches[1]
$apps = $appsString -split ',' | ForEach-Object { $_.Trim() -replace '"', '' } | Where-Object { $_ -ne '' }
$apps = $appsString -split ',' | ForEach-Object { $_.Trim().Trim('"').Trim("'") } | Where-Object { $_ -ne '' }
}
if ($apps.Count -eq 0) {
@@ -434,7 +479,23 @@ function Update-All {
}
# Voer het complete update script uit
$scriptPath = Split-Path -Parent $MyInvocation.ScriptName
$scriptPath = if ($MyInvocation.MyCommand.Path) {
Split-Path -Parent $MyInvocation.MyCommand.Path
} elseif ($MyInvocation.ScriptName) {
Split-Path -Parent $MyInvocation.ScriptName
} elseif ($PSCommandPath) {
Split-Path -Parent $PSCommandPath
} elseif ($PSScriptRoot) {
$PSScriptRoot
} else {
# When executed via .cmd wrapper, PUSHD sets current directory
$location = Get-Location
if ($location -is [System.IO.DirectoryInfo]) {
$location.FullName
} else {
$location.ToString()
}
}
$updateAllScript = Join-Path $scriptPath "scripts\update-all.cmd"
if (Test-Path $updateAllScript) {
@@ -505,7 +566,23 @@ function Enable-BitLocker {
Write-ColorText "Bestaande recovery key wordt opgeslagen..." "Yellow"
# Zorg dat output map bestaat
$scriptPath = Split-Path -Parent $MyInvocation.ScriptName
$scriptPath = if ($MyInvocation.MyCommand.Path) {
Split-Path -Parent $MyInvocation.MyCommand.Path
} elseif ($MyInvocation.ScriptName) {
Split-Path -Parent $MyInvocation.ScriptName
} elseif ($PSCommandPath) {
Split-Path -Parent $PSCommandPath
} elseif ($PSScriptRoot) {
$PSScriptRoot
} else {
# When executed via .cmd wrapper, PUSHD sets current directory
$location = Get-Location
if ($location -is [System.IO.DirectoryInfo]) {
$location.FullName
} else {
$location.ToString()
}
}
$outputPath = Join-Path $scriptPath "output"
if (-not (Test-Path $outputPath)) {
New-Item -ItemType Directory -Path $outputPath -Force | Out-Null
@@ -543,7 +620,23 @@ BELANGRIJK:
}
# Voer het BitLocker script uit
$scriptPath = Split-Path -Parent $MyInvocation.ScriptName
$scriptPath = if ($MyInvocation.MyCommand.Path) {
Split-Path -Parent $MyInvocation.MyCommand.Path
} elseif ($MyInvocation.ScriptName) {
Split-Path -Parent $MyInvocation.ScriptName
} elseif ($PSCommandPath) {
Split-Path -Parent $PSCommandPath
} elseif ($PSScriptRoot) {
$PSScriptRoot
} else {
# When executed via .cmd wrapper, PUSHD sets current directory
$location = Get-Location
if ($location -is [System.IO.DirectoryInfo]) {
$location.FullName
} else {
$location.ToString()
}
}
$bitlockerScript = Join-Path $scriptPath "scripts\enable-bitlocker.ps1"
if (Test-Path $bitlockerScript) {
+31
View File
@@ -79,6 +79,37 @@ if (-not (Test-BitLockerAvailable)) {
}
Write-Host "BitLocker is beschikbaar." -ForegroundColor Green
# Bepaal output path - als relatief pad wordt gegeven, maak het absoluut
if (-not [System.IO.Path]::IsPathRooted($OutputPath)) {
# Get script directory with fallback
$scriptDirPath = if ($MyInvocation.MyCommand.Path) {
Split-Path -Parent $MyInvocation.MyCommand.Path
} elseif ($PSCommandPath) {
Split-Path -Parent $PSCommandPath
} elseif ($PSScriptRoot) {
$PSScriptRoot
} else {
# When executed via .cmd wrapper, PUSHD sets current directory
$location = Get-Location
if ($location -is [System.IO.DirectoryInfo]) {
$location.FullName
} else {
$location.ToString()
}
}
# Resolve relative path (e.g., "..\output" from scripts/ should go to root/output/)
$resolvedPath = Resolve-Path (Join-Path $scriptDirPath $OutputPath) -ErrorAction SilentlyContinue
if ($resolvedPath) {
$OutputPath = $resolvedPath.Path
} else {
# Fallback: if resolving fails, try manual path construction
$parentDir = Split-Path -Parent $scriptDirPath
$relativePart = $OutputPath -replace '^\.\.\\', ''
$OutputPath = Join-Path $parentDir $relativePart
}
}
# Controleren of de output map bestaat
if (-not (Test-Path $OutputPath)) {
Write-Host "Output map wordt aangemaakt: $OutputPath" -ForegroundColor Yellow
+33 -3
View File
@@ -55,8 +55,29 @@ Write-Host ""
Write-Host "Bepaal gebruikerstype en laad app lijst..." -ForegroundColor Yellow
# Determine user type and load appropriate app list
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$parentDir = Split-Path -Parent $scriptDir
# 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"
@@ -108,7 +129,16 @@ if (-not (Test-Path $appsFile)) {
# Load apps from file
try {
Write-Host "Laad app lijst..." -ForegroundColor Yellow
. $appsFile
# 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
+35 -10
View File
@@ -20,24 +20,34 @@ function Write-Log {
# Probeer verschillende methoden om het script pad te bepalen
$scriptPath = $null
# Methode 1: Via $MyInvocation
if ($MyInvocation.ScriptName) {
# Methode 1: Via $MyInvocation.MyCommand.Path
if ($MyInvocation.MyCommand.Path) {
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
}
# Methode 2: Via $MyInvocation.ScriptName
if (-not $scriptPath -and $MyInvocation.ScriptName) {
$scriptPath = Split-Path -Parent $MyInvocation.ScriptName
}
# Methode 2: Via $PSCommandPath
# Methode 3: Via $PSCommandPath
if (-not $scriptPath -and $PSCommandPath) {
$scriptPath = Split-Path -Parent $PSCommandPath
}
# Methode 3: Via $PSScriptRoot
# Methode 4: Via $PSScriptRoot
if (-not $scriptPath -and $PSScriptRoot) {
$scriptPath = $PSScriptRoot
}
# Methode 4: Fallback naar huidige directory
# Methode 5: Fallback naar huidige directory (when executed via .cmd wrapper)
if (-not $scriptPath) {
$scriptPath = Get-Location
$location = Get-Location
if ($location -is [System.IO.DirectoryInfo]) {
$scriptPath = $location.FullName
} else {
$scriptPath = $location.ToString()
}
}
$logFile = Join-Path $scriptPath "update-log.txt"
@@ -441,14 +451,29 @@ Write-Host ""
# Bepaal log bestand locatie
$logPath = "update-log.txt"
try {
if ($MyInvocation.ScriptName) {
$scriptPath = $null
# Try multiple methods to determine script path
if ($MyInvocation.MyCommand.Path) {
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
} elseif ($MyInvocation.ScriptName) {
$scriptPath = Split-Path -Parent $MyInvocation.ScriptName
$logPath = Join-Path $scriptPath "update-log.txt"
} elseif ($PSCommandPath) {
$scriptPath = Split-Path -Parent $PSCommandPath
$logPath = Join-Path $scriptPath "update-log.txt"
} elseif ($PSScriptRoot) {
$logPath = Join-Path $PSScriptRoot "update-log.txt"
$scriptPath = $PSScriptRoot
} else {
# Fallback: when executed via .cmd wrapper, PUSHD sets current directory
$location = Get-Location
if ($location -is [System.IO.DirectoryInfo]) {
$scriptPath = $location.FullName
} else {
$scriptPath = $location.ToString()
}
}
if ($scriptPath) {
$logPath = Join-Path $scriptPath "update-log.txt"
}
} catch {
# Fallback naar huidige directory