2015-05-01 22:17:34 +02:00
|
|
|
#!powershell
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Copyright 2015, Peter Mounce <public@neverrunwithscissors.com>
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
|
|
|
# WANT_JSON
|
|
|
|
# POWERSHELL_COMMON
|
|
|
|
|
|
|
|
$params = Parse-Args $args;
|
|
|
|
$result = New-Object PSObject;
|
|
|
|
Set-Attr $result "changed" $false;
|
|
|
|
|
|
|
|
if ($params.name)
|
|
|
|
{
|
2015-05-02 14:56:01 +02:00
|
|
|
$name = $params.name
|
2015-05-01 22:17:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Fail-Json $result "missing required argument: name"
|
|
|
|
}
|
2015-05-19 12:21:23 +02:00
|
|
|
if ($params.enabled)
|
2015-05-01 22:17:34 +02:00
|
|
|
{
|
2015-05-19 12:21:23 +02:00
|
|
|
$enabled = $params.enabled | ConvertTo-Bool
|
2015-05-01 22:17:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-19 12:21:23 +02:00
|
|
|
$enabled = $true
|
2015-05-01 22:17:34 +02:00
|
|
|
}
|
2015-05-19 12:21:23 +02:00
|
|
|
$target_state = @{$true = "Enabled"; $false="Disabled"}[$enabled]
|
2015-05-01 22:17:34 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$tasks = Get-ScheduledTask -TaskPath $name
|
2015-05-19 12:21:23 +02:00
|
|
|
$tasks_needing_changing = $tasks |? { $_.State -ne $target_state }
|
2015-05-02 18:24:30 +02:00
|
|
|
if (-not($tasks_needing_changing -eq $null))
|
2015-05-01 22:17:34 +02:00
|
|
|
{
|
2015-05-19 12:21:23 +02:00
|
|
|
if ($enabled)
|
2015-05-01 22:17:34 +02:00
|
|
|
{
|
2015-05-19 12:21:23 +02:00
|
|
|
$tasks_needing_changing | Enable-ScheduledTask
|
2015-05-01 22:17:34 +02:00
|
|
|
}
|
2015-05-19 12:21:23 +02:00
|
|
|
else
|
2015-05-01 22:17:34 +02:00
|
|
|
{
|
2015-05-19 12:21:23 +02:00
|
|
|
$tasks_needing_changing | Disable-ScheduledTask
|
2015-05-01 22:17:34 +02:00
|
|
|
}
|
|
|
|
Set-Attr $result "tasks_changed" ($tasks_needing_changing | foreach { $_.TaskPath + $_.TaskName })
|
|
|
|
$result.changed = $true
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Set-Attr $result "tasks_changed" @()
|
|
|
|
$result.changed = $false
|
|
|
|
}
|
2015-05-02 18:24:30 +02:00
|
|
|
|
2015-05-01 22:17:34 +02:00
|
|
|
Exit-Json $result;
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
Fail-Json $result $_.Exception.Message
|
|
|
|
}
|