diff --git a/Win11Debloat.ps1 b/Win11Debloat.ps1 index 591e5f4..7224489 100644 --- a/Win11Debloat.ps1 +++ b/Win11Debloat.ps1 @@ -531,7 +531,7 @@ function RegImport { reg import "$PSScriptRoot\Regfiles\$path" } else { - $defaultUserPath = $env:USERPROFILE.Replace($env:USERNAME, 'Default\NTUSER.DAT') + $defaultUserPath = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), '\Default\NTUSER.DAT' reg load "HKU\Default" $defaultUserPath | Out-Null reg import "$PSScriptRoot\Regfiles\Sysprep\$path" @@ -575,7 +575,7 @@ function ReplaceStartMenuForAllUsers { } # Get path to start menu file for all users - $userPathString = $env:USERPROFILE.Replace($env:USERNAME, "*\AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState") + $userPathString = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), "\*\AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState" $usersStartMenuPaths = get-childitem -path $userPathString # Go through all users and replace the start menu file @@ -584,7 +584,7 @@ function ReplaceStartMenuForAllUsers { } # Also replace the start menu file for the default user profile - $defaultStartMenuPath = $env:USERPROFILE.Replace($env:USERNAME, 'Default\AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState') + $defaultStartMenuPath = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), '\Default\AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState' # Create folder if it doesn't exist if (-not(Test-Path $defaultStartMenuPath)) { @@ -757,7 +757,7 @@ else { } if ($global:Params.ContainsKey("Sysprep")) { - $defaultUserPath = $env:USERPROFILE.Replace($env:USERNAME, 'Default\NTUSER.DAT') + $defaultUserPath = $env:USERPROFILE -Replace ('\\' + $env:USERNAME + '$'), '\Default\NTUSER.DAT' # Exit script if default user directory or NTUSER.DAT file cannot be found if (-not (Test-Path "$defaultUserPath")) {