diff --git a/scripts/Windows/Scripts/Context.ps1 b/scripts/Windows/Scripts/Context.ps1 index 041100768..ad2439a4e 100644 --- a/scripts/Windows/Scripts/Context.ps1 +++ b/scripts/Windows/Scripts/Context.ps1 @@ -35,10 +35,30 @@ class Context { } [void] AddPowerShellProfileStatement([string] $statement) { - $this.AddPowerShellProfileStatement($null, $statement); + $this.AddPowerShellProfileStatement($true, $statement); } [void] AddPowerShellProfileStatement([string] $category, [string] $statement) { + $this.AddPowerShellProfileStatement($true, $category, $statement); + } + + [void] AddPowerShellProfileStatement([bool] $defaultUser, [string] $statement) { + $this.AddPowerShellProfileStatement($defaultUser, $null, $statement); + } + + [void] AddPowerShellProfileStatement([bool] $defaultUser, [string] $category, [string] $statement) { + [string] $userDir = $null; + + if ($defaultUser) { + $userDir = "C:\Users\Default"; + } else { + $userDir = "~"; + } + + $this.AddPowerShellProfileStatement($userDir, $category, $statement); + } + + [void] AddPowerShellProfileStatement([string] $userDir, [string] $category, [string] $statement) { Push-Location ~; $profileFiles = @((powershell -c '$PROFILE'), (pwsh -c '$PROFILE')) | ForEach-Object { Resolve-Path -Relative $_ }; @@ -47,7 +67,7 @@ class Context { } $profileFiles | ForEach-Object { - $fileName = "C:\Users\Default\$_"; + $fileName = "$userDir\$_"; $dirName = Split-Path -Parent $fileName; if (-not (Test-Path -PathType Container $dirName)) {