win_scheduled_task_stat - Get information about Windows Scheduled Tasks

New in version 2.5.

Synopsis

  • Will return whether the folder and task exists.
  • Returns the names of tasks in the folder specified.
  • If name is set and exists, will return information on the task itself.
  • Use win_scheduled_task to configure a scheduled task.

Parameters

Parameter Choices/Defaults Comments
name
The name of the scheduled task to get information for.
path Default:
"\\"
The folder path where the task lives.

Examples

- name: get information about a folder
  win_scheduled_task_stat:
    path: \folder name
  register: task_folder_stat

- name: get information about a task in the root folder
  win_scheduled_task_stat:
    name: task name
  register: task_stat

- name: get information about a task in a custom folder
  win_scheduled_task_stat:
    path: \folder name
    name: task name
  register: task_stat

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
actions
list
name is specified and task exists
A list of actions.

Sample:
[{'Arguments': '/c echo hi', 'Id': None, 'Path': 'cmd.exe', 'Type': 'TASK_ACTION_EXEC', 'WorkingDirectory': None}]
folder_exists
boolean
always
Whether the folder set at path exists.

Sample:
True
folder_task_count
int
always
The number of tasks that exist in the folder.

Sample:
2
folder_task_names
list
always
A list of tasks that exist in the folder.

Sample:
['Task 1', 'Task 2']
principal
complex
name is specified and task exists
Details on the principal configured to run the task.

display_name
str
The name of the user/group that is displayed in the Task Scheduler UI.

Sample:
Administrator
group_id
str
The group that will run the task.

Sample:
BUILTIN\Administrators
id
str
The ID for the principal.

Sample:
Author
logon_type
str
The logon method that the task will run with.

Sample:
TASK_LOGON_INTERACTIVE_TOKEN
run_level
str
The level of user rights used to run the task.

Sample:
TASK_RUNLEVEL_LUA
user_id
str
The user that will run the task.

Sample:
SERVER\Administrator
registration_info
complex
name is specified and task exists
Details on the task registration info.

author
str
The author os the task.

Sample:
SERVER\Administrator
date
str
The date when the task was register.

Sample:
2017-01-01T10:00:00
description
str
The description of the task.

Sample:
task description
documentation
str
The documentation of the task.

Sample:
task documentation
security_descriptor
str
The security descriptor of the task.

Sample:
security descriptor
source
str
The source of the task.

Sample:
source
uri
str
The URI/path of the task.

Sample:
\task\task name
version
str
The version of the task.

Sample:
1.0
settings
complex
name is specified and task exists
Details on the task settings.

allow_demand_start
bool
Whether the task can be started by using either the Run command of the Context menu.

Sample:
True
allow_hard_terminate
bool
Whether the task can terminated by using TerminateProcess.

Sample:
True
compatibility
int
The compatibility level of the task

Sample:
2
delete_expired_task_after
str
The amount of time the Task Scheduler will wait before deleting the task after it expires.

Sample:
PT10M
disallow_start_if_on_batteries
bool
Whether the task will not be started if the computer is running on battery power.

disallow_start_on_remote_app_session
bool
Whether the task will not be started when in a remote app session.

Sample:
True
enabled
bool
Whether the task is enabled.

Sample:
True
execution_time_limit
str
The amount of time allowed to complete the task.

Sample:
PT72H
hidden
bool
Whether the task is hidden in the UI.

idle_settings
dictionary
The idle settings of the task.

Sample:
{'idle_duration': 'PT10M', 'restart_on_idle': False, 'stop_on_idle_end': True, 'wait_timeout': 'PT1H'}
maintenance_settings
str
The maintenance settings of the task.

mulitple_instances
int
Indicates the behaviour when starting a task that is already running.

Sample:
2
network_settings
dictionary
The network settings of the task.

Sample:
{'id': None, 'name': None}
priority
int
The priority level of the task.

Sample:
7
restart_count
int
The number of times that the task will attempt to restart on failures.

restart_interval
str
How long the Task Scheduler will attempt to restart the task.

Sample:
PT15M
run_only_id_idle
bool
Whether the task will run if the computer is in an idle state.

Sample:
True
run_only_if_network_available
bool
Whether the task will run only when a network is available.

start_when_available
bool
Whether the task can start at any time after its scheduled time has passed.

stop_if_going_on_batteries
bool
Whether the task will be stopped if the computer begins to run on battery power.

Sample:
True
use_unified_scheduling_engine
bool
Whether the task will use the unifed scheduling engine.

volatile
bool
Whether thet ask is volatile.

wake_to_run
bool
Whether the task will wake the computer when it is time to run the task.

state
complex
name is specified and task exists
Details on the state of the task

last_run_time
str
The time the registered task was last run.

Sample:
2017-09-20T20:50:00
last_task_result
int
The results that were returned the last time the task was run.

Sample:
267009
next_run_time
str
The time when the task is next scheduled to run.

Sample:
2017-09-20T22:50:00
number_of_missed_runs
int
The number of times a task has missed a scheduled run.

Sample:
1
status
str
The status of the task, whether it is running, stopped, etc.

Sample:
TASK_STATE_RUNNING
task_exists
boolean
name is specified
Whether the task at the folder exists.

Sample:
True
triggers
list
name is specified and task exists
A list of triggers.

Sample:
[{'delay': 'PT15M', 'enabled': True, 'end_boundary': None, 'execution_time_limit': None, 'id': None, 'repetition': {'duration': None, 'interval': None, 'stop_at_duration_end': False}, 'start_boundary': None, 'type': 'TASK_TRIGGER_BOOT'}, {'days_of_month': '5,15,30', 'enabled': True, 'end_boundary': None, 'execution_time_limit': None, 'id': None, 'months_of_year': 'june,december', 'random_delay': None, 'repetition': {'duration': None, 'interval': None, 'stop_at_duration_end': False}, 'run_on_last_day_of_month': True, 'start_boundary': '2017-09-20T03:44:38', 'type': 'TASK_TRIGGER_MONTHLY'}]


Status

This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.

Maintenance

This module is flagged as community which means that it is maintained by the Ansible Community. See Module Maintenance & Support for more info.

For a list of other modules that are also maintained by the Ansible Community, see here.

Author

  • Jordan Borean (@jborean93)

Hint

If you notice any issues in this documentation you can edit this document to improve it.

© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.6/modules/win_scheduled_task_stat_module.html