PortValhalla/scripts/Windows/OS/User/Install.ps1

33 lines
808 B
PowerShell
Raw Normal View History

2024-03-23 14:38:06 +00:00
#!/bin/pwsh
. "$PSScriptRoot/../../Scripts/Context.ps1";
. "$PSScriptRoot/Add.ps1";
function Install-PersonalUsers([Context] $context) {
$userIDProperty = "User";
$null = New-Module {
2024-03-23 22:26:22 +00:00
function Get-UserID {
2024-03-23 14:38:06 +00:00
return $context.Get($userIDProperty);
}
2024-03-23 22:26:22 +00:00
function Set-UserID {
2024-03-23 14:38:06 +00:00
param([int]$value);
$context.Set($userIDProperty, $value);
}
}
$userID = Get-UserID;
if ($null -eq $userID) {
Set-UserID ($context.UserNames.Count - 1);
$userID = Get-UserID;
}
if ($userID -ge 0) {
New-PersonalUser $context $($context.UserNames[$userID]);
Set-UserID ($userID - 1);
2024-03-23 14:57:25 +00:00
} else {
Get-LocalUser | Where-Object { $_.Name -in $context.UserNames } |
Enable-LocalUser;
2024-03-23 14:38:06 +00:00
}
}