Reorder UAC disablement steps

This commit is contained in:
Manuel Thalmann 2023-06-29 17:27:00 +02:00
parent 0137fd56f3
commit 2dbd1a9fed

View file

@ -45,31 +45,13 @@ function New-PersonalUser([Context] $context)
Restart-Computer;
exit;
}
elseif ((Get-UACState))
elseif ((Get-LocalUser $context.AdminName))
{
Write-EventLog -LogName Application -Source "Application" -EventId $taskTrigger -Message "This event was created by $env:Username";
for ($i = 0; $i -lt $120; $i++)
{
if ((Get-UACState))
{
break;
}
}
if ((Get-UACState))
{
Write-Error "UAC Could not be disabled!";
Read-Host "Press enter to continue anyway";
}
Enable-CurrentUserAutologon $context;
Write-Information "Removing Admin Account";
Get-CimInstance -ClassName "Win32_UserProfile" -Filter "SID = $((Get-LocalUser $context.AdminName).SID)" | Remove-CimInstance;
Write-Host "Rebooting";
$context.Reboot();
Write-EventLog -LogName Application -Source "Application" -EventId $taskTrigger -Message "This event was created by $env:Username";
exit;
}
}