fix: win-scheduled-task strict-mode fixes
This commit is contained in:
parent
8973ecae5b
commit
572b6669c4
1 changed files with 15 additions and 30 deletions
|
@ -23,6 +23,13 @@ $ErrorActionPreference = "Stop"
|
|||
# POWERSHELL_COMMON
|
||||
|
||||
$params = Parse-Args $args;
|
||||
|
||||
$days_of_week = Get-Attr $params "days_of_week" $null;
|
||||
$enabled = Get-Attr $params "enabled" $true | ConvertTo-Bool;
|
||||
$description = Get-Attr $params "description" " ";
|
||||
$path = Get-Attr $params "path" $null;
|
||||
$argument = Get-Attr $params "argument" $null;
|
||||
|
||||
$result = New-Object PSObject;
|
||||
Set-Attr $result "changed" $false;
|
||||
|
||||
|
@ -40,33 +47,17 @@ if($state -eq "present") {
|
|||
$time = Get-Attr -obj $params -name time -failifempty $true -resultobj $result
|
||||
$user = Get-Attr -obj $params -name user -failifempty $true -resultobj $result
|
||||
}
|
||||
if ($params.days_of_week)
|
||||
|
||||
# Mandatory Vars
|
||||
if ($frequency -eq "weekly")
|
||||
{
|
||||
$days_of_week = $params.days_of_week
|
||||
}
|
||||
elseif ($frequency -eq "weekly")
|
||||
{
|
||||
Fail-Json $result "missing required argument: days_of_week"
|
||||
if (!($days_of_week))
|
||||
{
|
||||
Fail-Json $result "missing required argument: days_of_week"
|
||||
}
|
||||
}
|
||||
|
||||
# Vars with defaults
|
||||
if ($params.enabled)
|
||||
{
|
||||
$enabled = $params.enabled | ConvertTo-Bool
|
||||
}
|
||||
else
|
||||
{
|
||||
$enabled = $true #default
|
||||
}
|
||||
if ($params.description)
|
||||
{
|
||||
$description = $params.description
|
||||
}
|
||||
else
|
||||
{
|
||||
$description = " " #default
|
||||
}
|
||||
if ($params.path)
|
||||
if ($path)
|
||||
{
|
||||
$path = "\{0}\" -f $params.path
|
||||
}
|
||||
|
@ -75,12 +66,6 @@ else
|
|||
$path = "\" #default
|
||||
}
|
||||
|
||||
# Optional vars
|
||||
if ($params.argument)
|
||||
{
|
||||
$argument = $params.argument
|
||||
}
|
||||
|
||||
try {
|
||||
$task = Get-ScheduledTask -TaskPath "$path" | Where-Object {$_.TaskName -eq "$name"}
|
||||
|
||||
|
|
Loading…
Reference in a new issue