Add scripts for creating user

This commit is contained in:
Manuel Thalmann 2023-06-22 22:56:43 +02:00
parent bc2e4b8acb
commit 249b4d531c
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";
[Context]$context = [Context]::new();
$context.EntryPoint = "$($MyInvocation.MyCommand.Path)";
$context.UserName = "Manuel";
Invoke-WindowsInstallation $context;

View file

@ -1,11 +1,13 @@
. "$PSScriptRoot/../Scripts/Context.ps1";
. "$PSScriptRoot/Manage.ps1";
. "$PSScriptRoot/Upgrade.ps1";
. "$PSScriptRoot/User.ps1";
function Invoke-WindowsInstallation([Context] $context)
{
Write-Host "Starting Installation and Restoration of Windows";
. "$PSScriptRoot/../../../scripts/Windows/Scripts/Prerequisites.ps1";
Invoke-Upgrade $context;
New-PersonalUser $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]$RootDir;
[string]$BackupName;
[string]$UserName;
[string] BackupRoot() {
if (-not $this.RootDir)
{