$tskName     ="windowsRebootAndTaskDelete"
$tskDelay    ="300"
$tskDateTime ="2021-08-03 02:13:00"
$tskCommand  ="shutdown -r -t $tskDelay;schtasks.exe /delete /f /tn $tskName"
$tskPrincipal="NT AUTHORITY\SYSTEM"
$tskDateTime =[Datetime]::ParseExact($tskDateTime, 'yyyy-MM-dd HH:mm:ss', $null);$tskBase64Cmd=[Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($tskCommand));$tskAction=New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -EncodedCommand $tskBase64Cmd";$tskTrigger=New-ScheduledTaskTrigger -Once -At ($tskDateTime);$tskPrincipal=New-ScheduledTaskPrincipal -UserID "$tskPrincipal"
Register-ScheduledTask -TaskName "$tskName" -TaskPath "\" -Action $tskAction -Trigger $tskTrigger -Principal $tskPrincipal -Force
sleep 5
