Merge pull request #2074 from dreamcat4/feature/win-modules-strict-mode-fixes

Feature/win modules strict mode fixes
reviewable/pr18780/r1
Matt Davis 9 years ago
commit 7ece46711a

@ -20,11 +20,12 @@
# POWERSHELL_COMMON # POWERSHELL_COMMON
$params = Parse-Args $args; $params = Parse-Args $args;
$state = Get-Attr $params "state" $null;
$result = New-Object PSObject; $result = New-Object PSObject;
Set-Attr $result "changed" $false; Set-Attr $result "changed" $false;
If ($params.state) { If ($state) {
$state = $params.state.ToString().ToLower() $state = $state.ToString().ToLower()
If (($state -ne 'present') -and ($state -ne 'absent') ) { If (($state -ne 'present') -and ($state -ne 'absent') ) {
Fail-Json $result "state is '$state'; must be 'present', or 'absent'" Fail-Json $result "state is '$state'; must be 'present', or 'absent'"
} }

@ -20,6 +20,9 @@
# WANT_JSON # WANT_JSON
# POWERSHELL_COMMON # POWERSHELL_COMMON
# temporarily disable strictmode, for this module only
Set-StrictMode -Off
function getFirewallRule ($fwsettings) { function getFirewallRule ($fwsettings) {
try { try {

@ -23,6 +23,13 @@ $ErrorActionPreference = "Stop"
# POWERSHELL_COMMON # POWERSHELL_COMMON
$params = Parse-Args $args; $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; $result = New-Object PSObject;
Set-Attr $result "changed" $false; Set-Attr $result "changed" $false;
@ -40,33 +47,17 @@ if($state -eq "present") {
$time = Get-Attr -obj $params -name time -failifempty $true -resultobj $result $time = Get-Attr -obj $params -name time -failifempty $true -resultobj $result
$user = Get-Attr -obj $params -name user -failifempty $true -resultobj $result $user = Get-Attr -obj $params -name user -failifempty $true -resultobj $result
} }
if ($params.days_of_week)
{
$days_of_week = $params.days_of_week
}
elseif ($frequency -eq "weekly")
{
Fail-Json $result "missing required argument: days_of_week"
}
# Vars with defaults # Mandatory Vars
if ($params.enabled) if ($frequency -eq "weekly")
{
$enabled = $params.enabled | ConvertTo-Bool
}
else
{
$enabled = $true #default
}
if ($params.description)
{ {
$description = $params.description if (!($days_of_week))
} {
else Fail-Json $result "missing required argument: days_of_week"
{ }
$description = " " #default
} }
if ($params.path)
if ($path)
{ {
$path = "\{0}\" -f $params.path $path = "\{0}\" -f $params.path
} }
@ -75,12 +66,6 @@ else
$path = "\" #default $path = "\" #default
} }
# Optional vars
if ($params.argument)
{
$argument = $params.argument
}
try { try {
$task = Get-ScheduledTask -TaskPath "$path" | Where-Object {$_.TaskName -eq "$name"} $task = Get-ScheduledTask -TaskPath "$path" | Where-Object {$_.TaskName -eq "$name"}

Loading…
Cancel
Save