Last active
November 5, 2015 03:21
-
-
Save ryancurrah/a275228063cdbab50a35 to your computer and use it in GitHub Desktop.
schedule windows startup task using powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$execute = $args[0] | |
$argmuent = $args[1] | |
$working_directory = $args[2] | |
$task_name = $args[3] | |
$description = $args[4] | |
$get_task = Get-ScheduledTask $task_name -ErrorAction SilentlyContinue | |
if ($get_task) { | |
Write-Output "changed=no comment='Task name already exists, task not added.'" | |
} | |
else { | |
$action = New-ScheduledTaskAction -Execute $execute -Argument $argmuent -WorkingDirectory $working_directory | |
$trigger = New-ScheduledTaskTrigger -AtStartup | |
Register-ScheduledTask -Action $action -Trigger $trigger -User 'SYSTEM' -TaskName $task_name -Description $description | |
Write-Output "changed=yes comment='Task added succesfully.'" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment