Strict-Mode fixes

Changes to missing member handling to support running top-level script under Strict-Mode v2 (as Ansible 2.0.0 does now)
This commit is contained in:
nitzmahone 2015-10-27 16:08:00 -07:00 committed by Matt Clay
parent 426613b00d
commit 51b1cd061a

View file

@ -307,7 +307,7 @@ Function RunAsScheduledJob {
$schedjob = Register-ScheduledJob @rsj_args $schedjob = Register-ScheduledJob @rsj_args
# RunAsTask isn't available in PS3- fall back to a 2s future trigger # RunAsTask isn't available in PS3- fall back to a 2s future trigger
if($schedjob.RunAsTask) { if($schedjob | Get-Member -Name RunAsTask) {
Write-DebugLog "Starting scheduled job (PS4 method)" Write-DebugLog "Starting scheduled job (PS4 method)"
$schedjob.RunAsTask() $schedjob.RunAsTask()
} }
@ -337,8 +337,8 @@ Function RunAsScheduledJob {
$sw = [System.Diagnostics.Stopwatch]::StartNew() $sw = [System.Diagnostics.Stopwatch]::StartNew()
# NB: output from scheduled jobs is delayed after completion (including the sub-objects after the primary Output object is available) # NB: output from scheduled jobs is delayed after completion (including the sub-objects after the primary Output object is available)
While (($job.Output -eq $null -or $job.Output.job_output -eq $null) -and $sw.ElapsedMilliseconds -lt 15000) { While (($job.Output -eq $null -or -not $job.Output.Keys.Contains('job_output')) -and $sw.ElapsedMilliseconds -lt 15000) {
Write-DebugLog "Waiting for job output to be non-null..." Write-DebugLog "Waiting for job output to populate..."
Start-Sleep -Milliseconds 500 Start-Sleep -Milliseconds 500
} }
@ -351,7 +351,7 @@ Function RunAsScheduledJob {
DebugOutput = $job.Debug DebugOutput = $job.Debug
} }
If ($job.Output -eq $null -or $job.Output.job_output -eq $null) { If ($job.Output -eq $null -or -not $job.Output.Keys.Contains('job_output')) {
$ret.Output = @{failed = $true; msg = "job output was lost"} $ret.Output = @{failed = $true; msg = "job output was lost"}
} }
Else { Else {
@ -404,7 +404,7 @@ $parsed_args = Parse-Args $args $true
$parsed_args.psobject.properties | foreach -begin {$job_args=@{}} -process {$job_args."$($_.Name)" = $_.Value} -end {$job_args} $parsed_args.psobject.properties | foreach -begin {$job_args=@{}} -process {$job_args."$($_.Name)" = $_.Value} -end {$job_args}
# set the log_path for the global log function we injected earlier # set the log_path for the global log function we injected earlier
$log_path = $job_args.log_path $log_path = $job_args['log_path']
Log-Forensics Log-Forensics