Power Shell script to create a new Windows Task Scheduler entry
Hi,
I wrote a powershell script to create a new task in Windows Task Scheduler:
========================================
$action = New-ScheduledTaskAction -Execute "javaw" -Argument "-jar C:\caa-sourcetree\eqa\eQAclientApp\target\caalocalservice-exec.jar"
$trigger = New-ScheduledTaskTrigger -AtLogon
$principal = New-ScheduledTaskPrincipal -UserId "$($env:USERDOMAIN)$($env:USERNAME)" -LogonType ServiceAccount
$settings = New-ScheduledTaskSettingsSet
$task = New-ScheduledTask -Action $action -Principal $principal -Trigger $trigger -Settings $settings
Register-ScheduledTask CAATask -InputObject $task
========================================
I ran it inside Windows PowerShell with admin right and it did create a new task and the program works as I expected.
The only issue I have with new task is this condition:
This task needs to run regardless AC or DC power. Can you tell me how to modify my script so that it can create the task regardless AC or battery? We use Windows 11 Enterprise machines.
Your help will be appreciated.