Created
August 23, 2017 16:09
-
-
Save joshoohaah/4c2cdd936312d36f87263948ee5f7773 to your computer and use it in GitHub Desktop.
create an scheduled task with no trigger to execute
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
# Creates the Uninstall-Prerequisites scheduled task XML | |
template task_xml_path do | |
source 'uninstall-task.xml.erb' | |
variables( | |
user_id: user_id, | |
script_path: script_path, | |
log_path: log_path | |
) | |
action :create | |
end | |
task_command = ["schtasks.exe /Create /TN #{script}"] | |
task_command << "/XML #{task_xml_path}" | |
task_command << "/RU #{user_id}" | |
task_command << "/RP #{service_user['password']}" | |
# Creates the Uninstall-Prerequisites scheduled task with SCHTASKS.exe | |
# | |
# This is used instead of the windows_task resource because the resource does | |
# not support importing a scheduled task from an XML file. The XML file is used | |
# because there is no support with windows_task or SCHTASKS.EXE to set a | |
# trigger-less scheduled task without using an XML file. | |
execute "Create #{script} scheduled task" do | |
command task_command.join(' ') | |
guard_interpreter :powershell_script | |
only_if "$(Get-ScheduledTask -TaskName #{script}) -eq $null" | |
action :run | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment