I have below schedule task powershell script which creates a schedule task and runs under a service account.
$taskname = ''myscheduletask'
$action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument '-NoProfile -WindowStyle Hidden -command "& {stop-service -name "myservicename" -Force}"'
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddSeconds($delayinSeconds)
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName $taskname -Description $taskdescription -Force
After creating the schedule task, current default is 'Run only when user is logged on' however i want it to be "Run whether user is logged in or not" .
What settings i am missing here ? Just FYI: i cannot supply the password in this script.
Thanks
Update
At last i ended up using user name and password only which will be retrieved during the script run time.