2016-11-20 19:28:44 +00:00
---
title: About the windows_task Resource
2018-02-15 18:28:15 -06:00
platform: windows
2016-11-20 19:28:44 +00:00
---
# windows_task
2018-02-14 20:31:56 -08:00
Use the `windows_task` InSpec audit resource to test a scheduled tasks configuration on a Windows platform.
2018-03-20 21:43:30 +09:00
Microsoft and application vendors use scheduled tasks to perform a variety of system maintenance tasks but system administrators can schedule their own.
2016-11-20 19:28:44 +00:00
2017-10-03 14:35:10 -07:00
<br>
2018-08-09 08:34:49 -04:00
## Availability
### Installation
This resource is distributed along with InSpec itself. You can use it automatically.
### Version
This resource first became available in v1.10.0 of InSpec.
2016-11-20 19:28:44 +00:00
## Syntax
A `windows_task` resource block declares the name of the task (as its full path) and tests its configuration:
2017-03-01 13:43:26 -05:00
describe windows_task('task name uri') do
2016-11-20 19:28:44 +00:00
its('parameter') { should eq 'value' }
it { should be_enabled }
end
where
2017-10-03 14:35:10 -07:00
* `'parameter'` must be a valid parameter defined within this resource ie `logon_mode`, `last_result`, `task_to_run`, `run_as_user`
2016-11-20 19:28:44 +00:00
* `'value'` will be used to compare the value gather from your chosen parameter
2017-10-03 14:35:10 -07:00
* `'be_enabled'` is an example of a valid matcher that checks the state of a task, other examples are `exist` or `be_disabled`
2016-11-20 19:28:44 +00:00
2017-10-03 14:35:10 -07:00
<br>
2016-11-20 19:28:44 +00:00
## Examples
The following examples show how to use this InSpec resource.
2018-02-15 18:34:11 -08:00
### Tests that a task is enabled
describe windows_task('\Microsoft\Windows\Time Synchronization\SynchronizeTime') do
it { should be_enabled }
end
### Tests that a task is disabled
describe windows_task('\Microsoft\Windows\AppID\PolicyConverter') do
it { should be_disabled }
end
### Tests the configuration parameters of a task
describe windows_task('\Microsoft\Windows\AppID\PolicyConverter') do
its('logon_mode') { should eq 'Interactive/Background' }
its('last_result') { should eq '1' }
its('task_to_run') { should cmp '%Windir%\system32\appidpolicyconverter.exe' }
its('run_as_user') { should eq 'LOCAL SERVICE' }
end
### Tests that a task is defined
describe windows_task('\Microsoft\Windows\Defrag\ScheduledDefrag') do
it { should exist }
end
2016-11-20 19:28:44 +00:00
## Gathering Tasknames
2018-02-15 18:34:11 -08:00
2016-11-20 19:28:44 +00:00
Rather then use the GUI you can use the `schtasks.exe` to output a full list of tasks available on the system
`schtasks /query /FO list`
rather than use the `list` output you can use `CSV` if it is easier.
Please make sure you use the full TaskName (include the prefix `\`) within your control
2018-02-15 18:34:11 -08:00
C:\>schtasks /query /FO list
...
Folder: \Microsoft\Windows\Diagnosis
HostName: XPS15
TaskName: \Microsoft\Windows\Diagnosis\Scheduled
Next Run Time: N/A
Status: Ready
Logon Mode: Interactive/Background
...
2017-10-03 14:35:10 -07:00
<br>
## Matchers
2018-02-15 19:07:18 -08:00
For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).