community.windows.win_scheduled_task_stat 模块 – 获取 Windows 计划任务信息

注意

此模块是 community.windows 集合 (版本 2.3.0) 的一部分。

如果您使用的是 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.windows

要在剧本中使用它,请指定:community.windows.win_scheduled_task_stat

概要

参数

参数

注释

name

字符串

要获取信息的计划任务的名称。

如果设置了 name 且存在,则将返回有关任务本身的信息。

path

字符串

任务所在的文件夹路径。

默认值: "\\"

另请参阅

另请参阅

community.windows.win_scheduled_task

管理计划任务。

示例

- name: Get information about a folder
  community.windows.win_scheduled_task_stat:
    path: \folder name
  register: task_folder_stat

- name: Get information about a task in the root folder
  community.windows.win_scheduled_task_stat:
    name: task name
  register: task_stat

- name: Get information about a task in a custom folder
  community.windows.win_scheduled_task_stat:
    path: \folder name
    name: task name
  register: task_stat

返回值

常见的返回值已在 此处 记录,以下是此模块特有的字段

描述

actions

列表 / 元素=字符串

操作列表。

已返回:指定了 name 且任务存在

示例: [{"Arguments": "/c echo hi", "Id": null, "Path": "cmd.exe", "Type": "TASK_ACTION_EXEC", "WorkingDirectory": null}]

folder_exists

布尔值

path 设置的文件夹是否存在。

已返回:始终

示例: true

folder_task_count

整数

文件夹中存在的任务数量。

已返回:始终

示例: 2

folder_task_names

列表 / 元素=字符串

文件夹中存在的任务列表。

已返回:始终

示例: ["Task 1", "Task 2"]

principal

复杂类型

配置为运行任务的主体的详细信息。

已返回:指定了 name 且任务存在

display_name

字符串

在任务计划程序 UI 中显示的用户/组的名称。

示例: "Administrator"

group_id

字符串

将运行任务的组。

示例: "BUILTIN\\Administrators"

id

字符串

主体的 ID。

示例: "Author"

logon_type

字符串

任务将使用的登录方法。

示例: "TASK_LOGON_INTERACTIVE_TOKEN"

run_level

字符串

用于运行任务的用户权限级别。

示例: "TASK_RUNLEVEL_LUA"

user_id

字符串

将运行任务的用户。

示例: "SERVER\\Administrator"

registration_info

复杂类型

任务注册信息的详细信息。

已返回:指定了 name 且任务存在

author

字符串

任务的作者。

示例: "SERVER\\Administrator"

date

字符串

注册任务的日期。

示例: "2017-01-01T10:00:00"

description

字符串

任务的描述。

示例: "task description"

documentation

字符串

任务的文档。

示例: "task documentation"

security_descriptor

字符串

任务的安全描述符。

示例: "security descriptor"

source

字符串

任务的来源。

示例: "source"

uri

字符串

任务的 URI/路径。

示例: "\\task\\task name"

version

字符串

任务的版本。

示例: "1.0"

settings

复杂类型

任务设置的详细信息。

已返回:指定了 name 且任务存在

allow_demand_start

布尔值

任务是否可以使用“运行”命令或上下文菜单启动。

示例: true

allow_hard_terminate

布尔值

任务是否可以使用 TerminateProcess 终止。

示例: true

compatibility

整数

任务的兼容性级别

示例: 2

delete_expired_task_after

字符串

任务计划程序在任务过期后等待删除任务的时间。

示例: "PT10M"

disallow_start_if_on_batteries

布尔值

如果计算机正在使用电池供电,则任务是否不会启动。

示例: false

disallow_start_on_remote_app_session

布尔值

在远程应用程序会话中是否不会启动任务。

示例: true

enabled

布尔值

任务是否已启用。

示例: true

execution_time_limit

字符串

允许完成任务的时间。

示例: "PT72H"

hidden

布尔值

任务在UI中是否隐藏。

示例: false

idle_settings

字典

任务的空闲设置。

示例: {"idle_duration": "PT10M", "restart_on_idle": false, "stop_on_idle_end": true, "wait_timeout": "PT1H"}

maintenance_settings

字符串

任务的维护设置。

mulitple_instances

整数

指示启动已运行的任务时的行为。

示例: 2

network_settings

字典

任务的网络设置。

示例: {"id": null, "name": null}

priority

整数

任务的优先级。

示例: 7

restart_count

整数

任务在失败时尝试重新启动的次数。

示例: 0

restart_interval

字符串

任务计划程序尝试重新启动任务的时间。

示例: "PT15M"

run_only_id_idle

布尔值

如果计算机处于空闲状态,则任务是否运行。

示例: true

run_only_if_network_available

布尔值

只有在网络可用时任务是否运行。

示例: false

start_when_available

布尔值

任务是否可以在其计划时间过去后的任何时间启动。

示例: false

stop_if_going_on_batteries

布尔值

如果计算机开始使用电池供电,则任务是否停止。

示例: true

use_unified_scheduling_engine

布尔值

任务是否使用统一调度引擎。

示例: false

volatile

布尔值

任务是否易失。

示例: false

wake_to_run

布尔值

任务是否会在运行任务的时间唤醒计算机。

示例: false

state

复杂类型

任务状态的详细信息

已返回:指定了 name 且任务存在

last_run_time

字符串

注册的任务上次运行的时间。

示例: "2017-09-20T20:50:00"

last_task_result

整数

上次运行任务时返回的结果。

示例: 267009

next_run_time

字符串

任务下次计划运行的时间。

示例: "2017-09-20T22:50:00"

number_of_missed_runs

整数

任务错过计划运行的次数。

示例: 1

status

字符串

任务的状态,例如正在运行、已停止等。

示例: "TASK_STATE_RUNNING"

task_exists

布尔值

文件夹中是否存在该任务。

返回值: 指定名称

示例: true

triggers

列表 / 元素=字符串

触发器列表。

已返回:指定了 name 且任务存在

示例: [{"delay": "PT15M", "enabled": true, "end_boundary": null, "execution_time_limit": null, "id": null, "repetition": {"duration": null, "interval": null, "stop_at_duration_end": false}, "start_boundary": null, "type": "TASK_TRIGGER_BOOT"}, {"days_of_month": "5,15,30", "enabled": true, "end_boundary": null, "execution_time_limit": null, "id": null, "months_of_year": "june,december", "random_delay": null, "repetition": {"duration": null, "interval": null, "stop_at_duration_end": false}, "run_on_last_day_of_month": true, "start_boundary": "2017-09-20T03:44:38", "type": "TASK_TRIGGER_MONTHLY"}]

作者

  • Jordan Borean (@jborean93)