Allow creation of multiple users
This commit is contained in:
parent
f1310bafdf
commit
0246633c68
4 changed files with 41 additions and 12 deletions
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/pwsh
|
#!/bin/pwsh
|
||||||
. "$PSScriptRoot/Manage.ps1";
|
. "$PSScriptRoot/Manage.ps1";
|
||||||
. "$PSScriptRoot/Upgrade.ps1";
|
. "$PSScriptRoot/Upgrade.ps1";
|
||||||
. "$PSScriptRoot/User/Add.ps1";
|
. "$PSScriptRoot/User/Install.ps1";
|
||||||
. "$PSScriptRoot/../Scripts/Context.ps1";
|
. "$PSScriptRoot/../Scripts/Context.ps1";
|
||||||
. "$PSScriptRoot/../Software/Firefox/Install.ps1";
|
. "$PSScriptRoot/../Software/Firefox/Install.ps1";
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ function Invoke-WindowsInstallation([Context] $context)
|
||||||
{
|
{
|
||||||
$ErrorActionPreference = "Inquire";
|
$ErrorActionPreference = "Inquire";
|
||||||
. "$PSScriptRoot/../Scripts/Prerequisites.ps1";
|
. "$PSScriptRoot/../Scripts/Prerequisites.ps1";
|
||||||
$context.UserName ??= "Manuel";
|
$context.UserNames ??= @("Manuel");
|
||||||
Start-WindowsInstallation $context;
|
Start-WindowsInstallation $context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ function Start-WindowsInstallation([Context] $context) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$userStage {
|
$userStage {
|
||||||
New-PersonalUser $context;
|
Install-PersonalUsers $context;
|
||||||
$context.SetStage($restorationStage);
|
$context.SetStage($restorationStage);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ $preparedPasswordProperty = "AutoLoginPassword";
|
||||||
$autoLoginTriggerProperty = "AutoLoginTrigger";
|
$autoLoginTriggerProperty = "AutoLoginTrigger";
|
||||||
$uacDisablerTriggerProperty = "UACDisablerTrigger";
|
$uacDisablerTriggerProperty = "UACDisablerTrigger";
|
||||||
|
|
||||||
function New-PersonalUser([Context] $context)
|
function New-PersonalUser([Context] $context, [string] $userName)
|
||||||
{
|
{
|
||||||
$userStageProperty = "UserStage";
|
$userStageProperty = "UserStage";
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ function New-PersonalUser([Context] $context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not (Get-LocalUser $context.UserName -ErrorAction SilentlyContinue))
|
if (-not (Get-LocalUser $userName -ErrorAction SilentlyContinue))
|
||||||
{
|
{
|
||||||
Write-Host "Creating Personal User";
|
Write-Host "Creating Personal User";
|
||||||
|
|
||||||
|
@ -47,8 +47,8 @@ function New-PersonalUser([Context] $context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Information "Renaming the new User to $($context.UserName)";
|
Write-Information "Renaming the new User to $userName";
|
||||||
Rename-LocalUser $user $context.UserName;
|
Rename-LocalUser $user $userName;
|
||||||
Add-LocalGroupMember -Group "Administrators" -Member $user && Set-LocalUser $context.AdminName -Password (ConvertTo-SecureString -AsPlainText "Admin") && Disable-LocalUser $context.AdminName;
|
Add-LocalGroupMember -Group "Administrators" -Member $user && Set-LocalUser $context.AdminName -Password (ConvertTo-SecureString -AsPlainText "Admin") && Disable-LocalUser $context.AdminName;
|
||||||
|
|
||||||
Write-Host "Registering setup script for all new users";
|
Write-Host "Registering setup script for all new users";
|
||||||
|
@ -66,7 +66,7 @@ function New-PersonalUser([Context] $context)
|
||||||
|
|
||||||
switch (Get-UserStage) {
|
switch (Get-UserStage) {
|
||||||
"DisableUAC" {
|
"DisableUAC" {
|
||||||
Enable-PersonalUserAutologon $context;
|
Enable-PersonalUserAutologon $context $userName;
|
||||||
$context.RegisterReboot();
|
$context.RegisterReboot();
|
||||||
Set-UserStage "RemoveAdmin";
|
Set-UserStage "RemoveAdmin";
|
||||||
Start-EventDrivenTask $context.Get($uacDisablerTriggerProperty);
|
Start-EventDrivenTask $context.Get($uacDisablerTriggerProperty);
|
||||||
|
@ -123,7 +123,7 @@ function Enable-UACNextLogin([Context] $context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Enable-PersonalUserAutologon([Context] $context)
|
function Enable-PersonalUserAutologon([Context] $context, [string] $userName)
|
||||||
{
|
{
|
||||||
Add-Type -assemblyname System.DirectoryServices.AccountManagement;
|
Add-Type -assemblyname System.DirectoryServices.AccountManagement;
|
||||||
Write-Information "Re-Enabling Autologin for Current User";
|
Write-Information "Re-Enabling Autologin for Current User";
|
||||||
|
@ -133,7 +133,7 @@ function Enable-PersonalUserAutologon([Context] $context)
|
||||||
{
|
{
|
||||||
$password = Read-Host "Please enter the password of your Microsoft Account" -MaskInput;
|
$password = Read-Host "Please enter the password of your Microsoft Account" -MaskInput;
|
||||||
|
|
||||||
if ($principalContext.ValidateCredentials($context.UserName, $password))
|
if ($principalContext.ValidateCredentials($userName, $password))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ function Enable-PersonalUserAutologon([Context] $context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$context.Set($preparedUsernameProperty, $context.UserName, "ExpandString");
|
$context.Set($preparedUsernameProperty, $userName, "ExpandString");
|
||||||
$context.Set($preparedPasswordProperty, $password, "ExpandString");
|
$context.Set($preparedPasswordProperty, $password, "ExpandString");
|
||||||
Start-EventDrivenTask $context.Get($autoLoginTriggerProperty);
|
Start-EventDrivenTask $context.Get($autoLoginTriggerProperty);
|
||||||
}
|
}
|
||||||
|
|
29
scripts/Windows/OS/User/Install.ps1
Normal file
29
scripts/Windows/OS/User/Install.ps1
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#!/bin/pwsh
|
||||||
|
. "$PSScriptRoot/../../Scripts/Context.ps1";
|
||||||
|
. "$PSScriptRoot/Add.ps1";
|
||||||
|
|
||||||
|
function Install-PersonalUsers([Context] $context) {
|
||||||
|
$userIDProperty = "User";
|
||||||
|
|
||||||
|
$null = New-Module {
|
||||||
|
Get-UserID {
|
||||||
|
return $context.Get($userIDProperty);
|
||||||
|
}
|
||||||
|
Set-UserID {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ class Context {
|
||||||
[string]$EntryPoint;
|
[string]$EntryPoint;
|
||||||
[string]$RootDir;
|
[string]$RootDir;
|
||||||
[string]$BackupName;
|
[string]$BackupName;
|
||||||
[string]$UserName;
|
[string[]]$UserNames;
|
||||||
[string]$AdminName = "Admin";
|
[string]$AdminName = "Admin";
|
||||||
[string]$ConfigRoot = "HKLM:\Software\PortValhalla";
|
[string]$ConfigRoot = "HKLM:\Software\PortValhalla";
|
||||||
[string]$RunOnceName = "PortValhalla";
|
[string]$RunOnceName = "PortValhalla";
|
||||||
|
|
Loading…
Reference in a new issue