Skip to content

Commit e81c7e4

Browse files
authored
Refactor path handling for script root and logging
1 parent a4d1c53 commit e81c7e4

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

DeployWorkstation.ps1

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ $ErrorActionPreference = 'Continue'
2222
$ProgressPreference = 'Continue' # Must be Continue for Write-Progress to render
2323
$script:StartTime = Get-Date
2424

25-
if (-not $PSScriptRoot) {
26-
$PSScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
27-
}
25+
# $PSScriptRoot is read-only in PS5.1 — use a separate variable for fallback safety
26+
$scriptRoot = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path -Parent $MyInvocation.MyCommand.Path }
2827

29-
if (-not $LogPath) { $LogPath = Join-Path $PSScriptRoot 'DeployWorkstation.log' }
30-
if (-not $ReportPath) { $ReportPath = Join-Path $PSScriptRoot 'DeployWorkstation.html' }
28+
if (-not $LogPath) { $LogPath = Join-Path $scriptRoot 'DeployWorkstation.log' }
29+
if (-not $ReportPath) { $ReportPath = Join-Path $scriptRoot 'DeployWorkstation.html' }
3130

3231
# --------------------------------
3332
# Restart in Windows PowerShell 5.1 if running under PS Core
3433
# --------------------------------
3534
if ($PSVersionTable.PSEdition -eq 'Core') {
3635
Write-Warning 'PowerShell Core detected. Restarting in Windows PowerShell 5.1...'
37-
$params = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $PSCommandPath,
38-
'-LogPath', $LogPath, '-ReportPath', $ReportPath)
36+
# Wrap path values in escaped quotes so spaces in paths survive Start-Process argument joining
37+
$params = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', "`"$PSCommandPath`"",
38+
'-LogPath', "`"$LogPath`"", '-ReportPath', "`"$ReportPath`"")
3939
if ($SkipAppInstall) { $params += '-SkipAppInstall' }
4040
if ($SkipBloatwareRemoval) { $params += '-SkipBloatwareRemoval' }
4141
if ($SkipSystemConfig) { $params += '-SkipSystemConfig' }
@@ -1087,6 +1087,7 @@ try {
10871087

10881088
Set-OverallProgress -Status (T 'PhaseReporting') -Percent $script:PhasePct.ConfigEnd
10891089
Export-HtmlReport -OverallStatus $overallStatus
1090+
Set-OverallProgress -Status (T 'Completed') -Percent $script:PhasePct.Done
10901091

10911092
Write-Log "===== $(T 'Completed') =====" -Level 'SUCCESS'
10921093
Write-Host "`n*** $(T 'SetupComplete') ***" -ForegroundColor Green

0 commit comments

Comments
 (0)