Allow installing PowerShell scripts for the default user
This commit is contained in:
parent
0481482f23
commit
9918465b27
1 changed files with 26 additions and 15 deletions
|
@ -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,6 +55,21 @@ $null = New-Module {
|
|||
|
||||
Push-Location ~;
|
||||
$profiles = $profiles | ForEach-Object { [System.IO.Path]::GetRelativePath($(Get-Location), $_); };
|
||||
|
||||
$profiles | ForEach-Object {
|
||||
$fileName = "$HomeDir/$_";
|
||||
$dirName = Split-Path -Parent $fileName;
|
||||
|
||||
if (-not (Test-Path -PathType Container $dirName)) {
|
||||
$null = New-Item -ItemType Directory -Force $dirName;
|
||||
}
|
||||
|
||||
if ((Test-Path -PathType Leaf $fileName) -and (-not $Overwrite)) {
|
||||
Add-Content -Force "$fileName" "`n$Statement";
|
||||
} else {
|
||||
Set-Content -Force "$fileName" "$Statement";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if ($Category) {
|
||||
|
@ -54,21 +80,6 @@ $null = New-Module {
|
|||
$profiles = $profiles | ForEach-Object { Join-Path (Split-Path -Parent $_) "conf.d" "$Category.ps1"; };
|
||||
}
|
||||
|
||||
$profiles | ForEach-Object {
|
||||
$fileName = "$HomeDir/$_";
|
||||
$dirName = Split-Path -Parent $fileName;
|
||||
|
||||
if (-not (Test-Path -PathType Container $dirName)) {
|
||||
$null = New-Item -ItemType Directory -Force $dirName;
|
||||
}
|
||||
|
||||
if ((Test-Path -PathType Leaf $fileName) -and (-not $Overwrite)) {
|
||||
Add-Content -Force "$fileName" "`n$Statement";
|
||||
} else {
|
||||
Set-Content -Force "$fileName" "$Statement";
|
||||
}
|
||||
};
|
||||
|
||||
Pop-Location;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue