Skip to content

Instantly share code, notes, and snippets.

@joshoohaah
Created August 23, 2017 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshoohaah/4c2cdd936312d36f87263948ee5f7773 to your computer and use it in GitHub Desktop.
Save joshoohaah/4c2cdd936312d36f87263948ee5f7773 to your computer and use it in GitHub Desktop.
create an scheduled task with no trigger to execute
# 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