Scheduled Task that runs as SYSTEM but is triggered by a user action
and is on a delay.
Since you are using a random delay and it seems to be troublesome per timing, you should just use an explicit delay per each trigger event. Each trigger has its own setting for the delay this way.

Try the attached XML export from a job I setup on a system on my side changed up a bit to obscure real script and process names.
You can import it and then look over all the setup and configuration to see what all settings were set, make adjustments, etc.
Task Scheduler Job - XML Export
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2019-12-10T13:30:30.3849335</Date>
<Author>Administrator</Author>
<URI>\Kill Daemon</URI>
</RegistrationInfo>
<Principals>
<Principal id="Author">
<UserId>S-1-5-18</UserId>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
</Settings>
<Triggers>
<LogonTrigger>
<Delay>PT10S</Delay>
</LogonTrigger>
<SessionStateChangeTrigger>
<Delay>PT10S</Delay>
<StateChange>RemoteConnect</StateChange>
</SessionStateChangeTrigger>
<SessionStateChangeTrigger>
<Delay>PT10S</Delay>
<StateChange>ConsoleConnect</StateChange>
</SessionStateChangeTrigger>
</Triggers>
<Actions Context="Author">
<Exec>
<Command>Powershell</Command>
<Arguments>-ExecutionPolicy Bypass -File "C:\process\killit.ps1"</Arguments>
<WorkingDirectory>C:\process</WorkingDirectory>
</Exec>
</Actions>
</Task>
I want the (PoSh) script that runs to be able to identify which user
triggered the task
Because the trigger of the task is an event and not a user clicking on a script to execute a scheduled task, the PoSH script that executes cannot tell what user it was that logged on per the event that executes it.
This means doing simple logging and using $env:username will not give you the username that logged on causing the event.
How to identify which user triggered task?
You'd likely have to capture data from Event Viewer security logs at the time of execution to get the user account detail that logged on generating the event which triggers the Task Scheduler job, and incorporate that into the PoSH logic to save a log, etc.
You might be able to run the quser command and record the active session username and log it per PoSH logic that way too.
quser example output
C:\Users\ClownMan>quser
USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME
>ClownMan console 1 Active none 4/14/2021 7:46 AM
Additional PowerShell
(quser)[1].Split("").Where({$_.Trim() -ne ""})[0] -join " " -replace ">";
(quser)[1].Split("").Where({$_.Trim() -ne ""})[3];
(quser)[1].Split("").Where({$_.Trim() -ne ""})[5..7] -join " ";
Example Output
Note: With these values you could get the name of the user account that is active and then calculate with PowerShell to ensure the date and time is greater than one hour and only if it is to run the script per the hour delay condition.
ClownMan
Active
4/14/2021 7:46 AM
Additional Resources
$Env:Usernamevariable to a log file before the task scheduler execution or something like that. Just some quick ideas but I don't have time to test or write an answer at the moment. – Vomit IT - Chunky Mess Style Apr 22 '21 at 14:51quser. This would work if its on a machine that only one user can be logged onto at a time you can see which account is connected and active at the time of execution. – Vomit IT - Chunky Mess Style Apr 22 '21 at 15:02$Env:usernamewon't work. If you has a scheduled task that you execute with logic with a logged on user to execute the task that executes the script asSYSTEMthen that's what I was talking about. I wasn't sure how a user was executing it I guess. You should keep track of user account login time and correlate that with some log that shows when the task ran asSYSTEMafter the delay. The delay does seem troublesome in this case for what you're asking. – Vomit IT - Chunky Mess Style Apr 22 '21 at 15:44<RandomDelay>. How do you create a "standard one" and control it?Edit:I just found there is also a possible xml node of just<Delay>. not sure if it's adjustable in the GUI. – Teknowledgist Apr 22 '21 at 16:45