diff --git a/Scripts/Features/ReplaceStartMenu.ps1 b/Scripts/Features/ReplaceStartMenu.ps1 index 6c3eb8b..c9e14ae 100644 --- a/Scripts/Features/ReplaceStartMenu.ps1 +++ b/Scripts/Features/ReplaceStartMenu.ps1 @@ -228,7 +228,9 @@ function RestoreStartMenuFromBackup { $userName = GetStartMenuUserNameFromPath -StartMenuBinFile $StartMenuBinFile $backupTimestamp = (Get-Date).ToString('yyyyMMdd_HHmmss') $startMenuBackupsDir = Join-Path $script:AppDataPath 'Backups' - $backupBinFile = if ([string]::IsNullOrWhiteSpace($BackupFilePath)) { + if (-not (Test-Path $startMenuBackupsDir)) { New-Item -ItemType Directory -Path $startMenuBackupsDir -Force | Out-Null } + + $resolvedBackupPath = if ([string]::IsNullOrWhiteSpace($BackupFilePath)) { Join-Path $startMenuBackupsDir "Win11Debloat-Start2BinBackup-$userName-$backupTimestamp.bak" } else { @@ -237,7 +239,7 @@ function RestoreStartMenuFromBackup { $currentBinBackup = Join-Path $startMenuBackupsDir "Win11Debloat-Start2BinRestore-$userName-$backupTimestamp.bak" if ($script:Params.ContainsKey("WhatIf")) { - Write-Host "[WhatIf] Restore start menu for user $userName from backup $BackupFilePath" -ForegroundColor Cyan + Write-Host "[WhatIf] Restore start menu for user $userName from backup $resolvedBackupPath" -ForegroundColor Cyan return [PSCustomObject]@{ UserName = $userName Result = $true @@ -245,11 +247,11 @@ function RestoreStartMenuFromBackup { } } - if (-not (Test-Path -LiteralPath $BackupFilePath)) { + if (-not (Test-Path -LiteralPath $resolvedBackupPath)) { return [PSCustomObject]@{ UserName = $userName Result = $false - Message = "Start menu backup file not found: $BackupFilePath" + Message = "Start menu backup file not found: $resolvedBackupPath" } } @@ -258,7 +260,7 @@ function RestoreStartMenuFromBackup { Move-Item -Path $StartMenuBinFile -Destination $currentBinBackup -Force } - Copy-Item -Path $BackupFilePath -Destination $StartMenuBinFile -Force + Copy-Item -Path $resolvedBackupPath -Destination $StartMenuBinFile -Force return [PSCustomObject]@{ UserName = $userName Result = $true diff --git a/Win11Debloat.ps1 b/Win11Debloat.ps1 index ff2f8b2..aff47c9 100644 --- a/Win11Debloat.ps1 +++ b/Win11Debloat.ps1 @@ -212,6 +212,9 @@ Write-Host "" Write-Host "" # Log script output to 'Win11Debloat.log' at the specified path +$logDir = if ($LogPath) { $LogPath } else { Split-Path $script:DefaultLogPath -Parent } +if (-not (Test-Path $logDir)) { New-Item -ItemType Directory -Path $logDir -Force | Out-Null } + if ($LogPath -and (Test-Path $LogPath)) { Start-Transcript -Path (Join-Path $LogPath 'Win11Debloat.log') -Append -IncludeInvocationHeader -Force | Out-Null }