Detect current step using stages

This commit is contained in:
Manuel Thalmann 2023-06-29 19:13:33 +02:00
parent 32fd5aa572
commit 6f011a2600

View file

@ -42,15 +42,17 @@ function New-PersonalUser([Context] $context)
Write-Information "Disabling Auto login"; Write-Information "Disabling Auto login";
$context.RemoveAutologin(); $context.RemoveAutologin();
$context.SetStage("DisableUAC");
Restart-Computer; Restart-Computer;
exit; exit;
} }
elseif ((Get-LocalUser $context.AdminName)) elseif ($context.GetStage() -eq "DisableUAC")
{ {
Enable-PersonalUserAutologon $context; Enable-PersonalUserAutologon $context;
Write-Information "Removing Admin Account"; Write-Information "Removing Admin Account";
Get-CimInstance -ClassName "Win32_UserProfile" -Filter "SID = $((Get-LocalUser $context.AdminName).SID)" | Remove-CimInstance; Get-CimInstance -ClassName "Win32_UserProfile" -Filter "SID = $((Get-LocalUser $context.AdminName).SID)" | Remove-CimInstance;
$context.RegisterReboot(); $context.RegisterReboot();
$context.RemoveStage();
Write-EventLog -LogName Application -Source "Application" -EventId $taskTrigger -Message "This event was created by $env:Username"; Write-EventLog -LogName Application -Source "Application" -EventId $taskTrigger -Message "This event was created by $env:Username";
exit; exit;
} }