Allow choosing where to create PowerShell profiles to

This commit is contained in:
Manuel Thalmann 2023-07-27 02:54:14 +02:00
parent 466dd8feff
commit f70513f234

View file

@ -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)) {