Post-setup scheduled task not working

sjackaman

New Member
Messages
6
Reaction score
1
Hi there,

I want to setup a scheduled task with an after-logon post-setup command. Before logon, I move an .xml file for the scheduled task to \Windows\Setup\DisableAdmin.xml and then after logon run the following command:

Task: powershell
Parameters: $xmlPath="C:\Windows\Setup\DisableAdmin.xml";$taskName="DisableAdmin";$startTime=(Get-Date).AddDays(3).ToString("yyyy-MM-ddTHH:mm:ss");[xml]$taskXml=Get-Content $xmlPath -Raw;$taskXml.Task.Triggers.TimeTrigger.StartBoundary=$startTime;$taskXml.Save($xmlPath);schtasks /Create /TN $taskName /XML $xmlPath

If I run this locally on my Windows machine, it created the scheduled task, but when building a device with the NTLite ISO, it does not create the scheduled task. The scheduled task is to disable the administrator account after 3 days.

1765982335856.png
1765982347778.png
 
Passing a long command line to PS will get you into trouble, I suspect the problem is the entire line isn't surrounded by quotes.

A better answer is to move everything into a single PS script, and submit the script to Post-Setup without any parameters.
Code:
$StartTime = [datetime](Get-Date).AddDays(3)

$Action = New-ScheduledTaskAction -Execute 'net' -Argument 'user administrator /active:no'
$Trigger = New-ScheduledTaskTrigger -Once -At $StartTime
$Principal = New-ScheduledTaskPrincipal -UserId 'NT AUTHORITY\System' -LogonType ServiceAccount -RunLevel Highest

Register-ScheduledTask -TaskName 'DisableAdmin' -Action $Action -Trigger $Trigger -Principal $Principal -Description "This task disables the built-in Administrator user in 3 days"
 
Back
Top