Add scripts for creating user

This commit is contained in:
Manuel Thalmann 2023-06-22 22:56:43 +02:00
parent 4a88657bf5
commit 4668ffc42a
4 changed files with 27 additions and 0 deletions

View file

@ -5,4 +5,5 @@ Write-Host "Starting Restoration of Windows";
. "$PSScriptRoot/../../../scripts/Windows/OS/Install.ps1"; . "$PSScriptRoot/../../../scripts/Windows/OS/Install.ps1";
[Context]$context = [Context]::new(); [Context]$context = [Context]::new();
$context.EntryPoint = "$($MyInvocation.MyCommand.Path)"; $context.EntryPoint = "$($MyInvocation.MyCommand.Path)";
$context.UserName = "Manuel";
Invoke-WindowsInstallation $context; Invoke-WindowsInstallation $context;

View file

@ -1,5 +1,6 @@
. "$PSScriptRoot/Manage.ps1"; . "$PSScriptRoot/Manage.ps1";
. "$PSScriptRoot/Upgrade.ps1"; . "$PSScriptRoot/Upgrade.ps1";
. "$PSScriptRoot/User.ps1";
. "$PSScriptRoot/../Scripts/Context.ps1"; . "$PSScriptRoot/../Scripts/Context.ps1";
function Invoke-WindowsInstallation([Context] $context) function Invoke-WindowsInstallation([Context] $context)
@ -7,5 +8,6 @@ function Invoke-WindowsInstallation([Context] $context)
Write-Host "Starting Installation and Restoration of Windows"; Write-Host "Starting Installation and Restoration of Windows";
. "$PSScriptRoot/../Scripts/Prerequisites.ps1"; . "$PSScriptRoot/../Scripts/Prerequisites.ps1";
Invoke-Upgrade $context; Invoke-Upgrade $context;
New-PersonalUser $context;
Invoke-WindowsRestore $context; Invoke-WindowsRestore $context;
} }

View file

@ -0,0 +1,23 @@
. "$PSScriptRoot/../Scripts/Context.ps1";
function New-PersonalUser([Context] $context)
{
Write-Host "Creating Personal User";
if (-not (Get-LocalUser $context.UserName))
{
Write-Host (
[string]::Join(
"`n",
"So... Windows is too dumb to create users which are bound to a Microsoft Account.",
"Thus, you have to do it by yourself.",
"So sorry..."));
$users = Get-LocalUser | Select-Object { $_.Name };
Read-Host "Please hit enter once you're done...";
$user = Get-LocalUser | Select-Object { -not ($users -contains $_.Name) } | Select-Object -Last;
Rename-LocalUser $user $context.UserName;
Add-LocalGroupMember -Group "Administrators" -Member $user;
}
}

View file

@ -2,6 +2,7 @@ class Context {
[string]$EntryPoint; [string]$EntryPoint;
[string]$RootDir; [string]$RootDir;
[string]$BackupName; [string]$BackupName;
[string]$UserName;
[string] BackupRoot() { [string] BackupRoot() {
if (-not $this.RootDir) if (-not $this.RootDir)
{ {