Remove admin account in a separate stage

This commit is contained in:
Manuel Thalmann 2023-06-30 04:29:59 +02:00
parent fa0a0356a4
commit 24466aef7a

View file

@ -51,13 +51,16 @@ function New-PersonalUser([Context] $context)
elseif ($context.GetStage() -eq "DisableUAC")
{
Enable-PersonalUserAutologon $context;
Write-Information "Removing Admin Account";
Get-CimInstance -ClassName "Win32_UserProfile" -Filter "SID = '$((Get-LocalUser $context.AdminName).SID)'" | Remove-CimInstance;
$context.RegisterReboot();
$context.RemoveStage();
$context.SetStage("RemoveAdmin");
Write-EventLog -LogName Application -Source "Application" -EventId $context.Get($uacDisablerTriggerProperty) -Message "This event was created by $env:Username";
exit;
}
elseif ($context.GetStage() -eq "RemoveAdmin")
{
Write-Information "Removing Admin Account";
Get-CimInstance -ClassName "Win32_UserProfile" -Filter "SID = '$((Get-LocalUser $context.AdminName).SID)'" | Remove-CimInstance;
}
}
function Get-SystemPolicyKey() {