Add script for enabling autologin
This commit is contained in:
parent
fcc02320ea
commit
39c2db4414
1 changed files with 23 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue