Add script for enabling autologin

This commit is contained in:
Manuel Thalmann 2023-06-28 22:50:39 +02:00
parent fcc02320ea
commit 39c2db4414

View file

@ -60,6 +60,7 @@ function New-PersonalUser([Context] $context)
}
Start-ScheduledTask $cleanupName;
Enable-CurrentUserAutologon $context;
}
}
@ -91,3 +92,25 @@ function Enable-UACNextLogin() {
$task = New-ScheduledTask -Action $action -Principal $principal;
$null = Register-ScheduledTask $cleanupName -InputObject $task;
}
function Enable-CurrentUserAutologon([Context] $context)
{
Add-Type -assemblyname System.DirectoryServices.AccountManagement;
Write-Information "Re-Enabling Autologin for Current User";
$principalContext = [System.DirectoryServices.AccountManagement.PrincipalContext]::new("Machine");
while ($true)
{
$password = Read-Host "Please enter the password of your user" -MaskInput;
if ($principalContext.ValidateCredentials($context.UserName, $password))
{
break;
}
else {
Write-Error "The specified password is incorrect!";
}
}
$context.SetAutologin($context.UserName, $password);
}