Remove admin account in a separate stage
This commit is contained in:
parent
fa0a0356a4
commit
24466aef7a
1 changed files with 6 additions and 3 deletions
|
@ -51,13 +51,16 @@ function New-PersonalUser([Context] $context)
|
||||||
elseif ($context.GetStage() -eq "DisableUAC")
|
elseif ($context.GetStage() -eq "DisableUAC")
|
||||||
{
|
{
|
||||||
Enable-PersonalUserAutologon $context;
|
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.RegisterReboot();
|
||||||
$context.RemoveStage();
|
$context.SetStage("RemoveAdmin");
|
||||||
Write-EventLog -LogName Application -Source "Application" -EventId $context.Get($uacDisablerTriggerProperty) -Message "This event was created by $env:Username";
|
Write-EventLog -LogName Application -Source "Application" -EventId $context.Get($uacDisablerTriggerProperty) -Message "This event was created by $env:Username";
|
||||||
exit;
|
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() {
|
function Get-SystemPolicyKey() {
|
||||||
|
|
Loading…
Reference in a new issue