Allow installing PowerShell scripts for the default user

This commit is contained in:
Manuel Thalmann 2024-03-21 00:06:34 +01:00
parent 1bc0226ca7
commit 3f09c682f6

View file

@ -4,9 +4,12 @@ $null = New-Module {
param (
[Parameter(ParameterSetName="Global", Mandatory)]
[switch]$System,
[Parameter(ParameterSetName="DefaultUser", Mandatory)]
[switch]$DefaultUser,
[Parameter(ParameterSetName="Home")]
[string]$HomeDir = "~",
[Parameter(ParameterSetName="Global", Mandatory)]
[Parameter(ParameterSetName="DefaultUser")]
[Parameter(ParameterSetName="Home")]
[string]$Category = $null,
[Parameter(Position=0, Mandatory=$true)]
@ -29,6 +32,14 @@ $null = New-Module {
} else {
[System.Collections.Generic.List[string]] $shells = @();
if ($DefaultUser) {
if ($IsWindows) {
$HomeDir = "C:/Users/Default";
} else {
$HomeDir = "/etc/skel"
}
}
if (Get-Command pwsh -ErrorAction SilentlyContinue) {
$shells.Add("pwsh");
}
@ -44,15 +55,6 @@ $null = New-Module {
Push-Location ~;
$profiles = $profiles | ForEach-Object { [System.IO.Path]::GetRelativePath($(Get-Location), $_); };
}
if ($Category) {
if (-not $($Overwrite.IsPresent)) {
$Overwrite = $true;
}
$profiles = $profiles | ForEach-Object { Join-Path (Split-Path -Parent $_) "conf.d" "$Category.ps1"; };
}
$profiles | ForEach-Object {
$fileName = "$HomeDir/$_";
@ -68,6 +70,15 @@ $null = New-Module {
Set-Content -Force "$fileName" "$Statement";
}
};
}
if ($Category) {
if (-not $($Overwrite.IsPresent)) {
$Overwrite = $true;
}
$profiles = $profiles | ForEach-Object { Join-Path (Split-Path -Parent $_) "conf.d" "$Category.ps1"; };
}
Pop-Location;
}