2023-06-22 20:56:43 +00:00
|
|
|
. "$PSScriptRoot/../Scripts/Context.ps1";
|
|
|
|
|
|
|
|
function New-PersonalUser([Context] $context)
|
|
|
|
{
|
|
|
|
if (-not (Get-LocalUser $context.UserName))
|
|
|
|
{
|
2023-06-23 12:04:46 +00:00
|
|
|
Write-Host "Creating Personal User";
|
|
|
|
|
2023-06-22 21:36:45 +00:00
|
|
|
while ($true) {
|
|
|
|
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..."));
|
2023-06-22 20:56:43 +00:00
|
|
|
|
2023-06-23 10:34:12 +00:00
|
|
|
$users = Get-LocalUser | ForEach-Object { $_.Name };
|
2023-06-23 00:34:53 +00:00
|
|
|
Write-Host "Following users exist already:"
|
|
|
|
Write-Host $users;
|
2023-06-22 21:36:45 +00:00
|
|
|
Read-Host "Please hit enter once you're done...";
|
|
|
|
|
2023-06-22 21:39:49 +00:00
|
|
|
$user = Get-LocalUser | Where-Object { -not ($users -contains $_.Name) } | Select-Object -Last 1;
|
2023-06-22 21:36:45 +00:00
|
|
|
|
|
|
|
if ($user) {
|
2023-06-22 22:20:30 +00:00
|
|
|
Write-Information "Found New User:";
|
|
|
|
Write-Information $user;
|
2023-06-22 21:36:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-06-22 20:56:43 +00:00
|
|
|
|
2023-06-23 18:16:47 +00:00
|
|
|
Write-Information "Renaming the new User to $($context.UserName)";
|
2023-06-22 20:56:43 +00:00
|
|
|
Rename-LocalUser $user $context.UserName;
|
2023-06-22 21:41:43 +00:00
|
|
|
Add-LocalGroupMember -Group "Administrators" -Member $user && Set-LocalUser $context.AdminName -Password (ConvertTo-SecureString -AsPlainText "Admin");
|
2023-06-23 18:16:47 +00:00
|
|
|
|
|
|
|
Write-Host "Registering setup script for all new users";
|
|
|
|
$context.RegisterNewUserReboot();
|
|
|
|
Register-Reboot;
|
2023-06-22 20:56:43 +00:00
|
|
|
}
|
|
|
|
}
|