Code-review

Swap state enabled/disabled -> enabled yes/no
reviewable/pr18780/r1
Peter Mounce 10 years ago
parent d9211b709b
commit a4a3a13439

@ -33,33 +33,29 @@ else
{
Fail-Json $result "missing required argument: name"
}
if ($params.state)
if ($params.enabled)
{
$state = $params.state.ToString()
if (($state -ne 'Enabled') -and ($state -ne 'Disabled'))
{
Fail-Json $result "state is '$state'; must be 'Enabled' or 'Disabled'"
}
$enabled = $params.enabled | ConvertTo-Bool
}
else
{
$state = "Enabled"
$enabled = $true
}
$target_state = @{$true = "Enabled"; $false="Disabled"}[$enabled]
try
{
$tasks = Get-ScheduledTask -TaskPath $name
$tasks_needing_changing = $tasks |? { $_.State -ne $state }
$tasks_needing_changing = $tasks |? { $_.State -ne $target_state }
if (-not($tasks_needing_changing -eq $null))
{
if ($state -eq 'Disabled')
if ($enabled)
{
$tasks_needing_changing | Disable-ScheduledTask
$tasks_needing_changing | Enable-ScheduledTask
}
elseif ($state -eq 'Enabled')
else
{
$tasks_needing_changing | Enable-ScheduledTask
$tasks_needing_changing | Disable-ScheduledTask
}
Set-Attr $result "tasks_changed" ($tasks_needing_changing | foreach { $_.TaskPath + $_.TaskName })
$result.changed = $true

@ -34,18 +34,18 @@ options:
- Name of the scheduled task
- Supports * as wildcard
required: true
state:
enabled:
description:
- State that the task should become
required: false
choices:
- Disabled
- Enabled
default: Enabled
- yes
- no
default: yes
author: Peter Mounce
'''
EXAMPLES = '''
# Disable the scheduled tasks with "WindowsUpdate" in their name
win_scheduled_task: name="*WindowsUpdate*" state=disabled
win_scheduled_task: name="*WindowsUpdate*" enabled=no
'''

Loading…
Cancel
Save