Skip to content

Commit 92d505b

Browse files
committed
Account for different return value of server for repetition
1 parent 801a9be commit 92d505b

1 file changed

Lines changed: 51 additions & 27 deletions

File tree

DSCResources/MSFT_xScheduledTask/MSFT_xScheduledTask.psm1

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -62,39 +62,63 @@ function Get-TargetResource
6262
$repetition = $trigger.Repetition
6363
$returnScheduleType = "Unknown"
6464
$returnInveral = 0
65-
Write-Verbose -Message "Duration: '$($repetition.Duration)'"
66-
Write-Verbose -Message "Interval: '$($repetition.Interval)'"
67-
if ($repetition.Duration -eq $null -and $repetition.Interval -eq $null)
68-
{
69-
$returnScheduleType = "Daily"
70-
$returnInveral = $trigger.DaysInterval
71-
}
72-
if ($repetition.Duration -eq $null -and $repetition.Interval -like "P*D")
73-
{
74-
$returnScheduleType = "Daily"
75-
[System.Uint32]$returnInveral = $repetition.Interval -replace "P" -replace "D"
76-
}
77-
if (($repetition.Duration -eq "P1D" -or $repetition.Duration -eq $null) `
78-
-and $repetition.Interval -like "PT*H")
65+
66+
# Check for full formatting
67+
if ($repetition.Interval -like "P*DT*H*M*S")
7968
{
80-
$returnScheduleType = "Hourly"
81-
[System.Uint32]$returnInveral = $repetition.Interval -replace "PT" -replace "H"
82-
}
83-
if (($repetition.Duration -eq "P1D" -or $repetition.Duration -eq $null) `
84-
-and $repetition.Interval -like "PT*M")
69+
$timespan = [Timespan]::Parse(($repetition.Interval -replace "P" -replace "DT", ":" -replace "H", ":" -replace "M", ":" -replace "S"))
70+
71+
$timespan = New-TimeSpan -Days 1
72+
if ($timespan.Days -ge 1)
73+
{
74+
$returnScheduleType = "Daily"
75+
$returnInveral = $timespan.TotalDays
76+
}
77+
elseif ($timespan.Hours -ge 1 -and $timespan.Minutes -eq 0)
78+
{
79+
$returnScheduleType = "Hourly"
80+
$returnInveral = $timespan.TotalHours
81+
}
82+
elseif ($timespan.Minutes -ge 1)
83+
{
84+
$returnScheduleType = "Minutes"
85+
$returnInveral = $timespan.TotalMinutes
86+
}
87+
}
88+
else
8589
{
86-
$returnScheduleType = "Minutes"
87-
if ($repetition.Interval.Contains('H'))
90+
if ($repetition.Duration -eq $null -and $repetition.Interval -eq $null)
8891
{
89-
$timeToParse = ($repetition.Interval -replace "PT" -replace "H",":" -replace "M")
90-
[System.Uint32]$returnInveral = [TimeSpan]::Parse($timeToParse).TotalMinutes
91-
}
92-
else
92+
$returnScheduleType = "Daily"
93+
$returnInveral = $trigger.DaysInterval
94+
}
95+
if ($repetition.Duration -eq $null -and $repetition.Interval -like "P*D")
9396
{
94-
[System.Uint32]$returnInveral = $repetition.Interval -replace "PT" -replace "M"
97+
$returnScheduleType = "Daily"
98+
[System.Uint32]$returnInveral = $repetition.Interval -replace "P" -replace "D"
99+
}
100+
if (($repetition.Duration -eq "P1D" -or $repetition.Duration -eq $null) `
101+
-and $repetition.Interval -like "PT*H")
102+
{
103+
$returnScheduleType = "Hourly"
104+
[System.Uint32]$returnInveral = $repetition.Interval -replace "PT" -replace "H"
105+
}
106+
if (($repetition.Duration -eq "P1D" -or $repetition.Duration -eq $null) `
107+
-and $repetition.Interval -like "PT*M")
108+
{
109+
$returnScheduleType = "Minutes"
110+
if ($repetition.Interval.Contains('H'))
111+
{
112+
$timeToParse = ($repetition.Interval -replace "PT" -replace "H",":" -replace "M")
113+
[System.Uint32]$returnInveral = [TimeSpan]::Parse($timeToParse).TotalMinutes
114+
}
115+
else
116+
{
117+
[System.Uint32]$returnInveral = $repetition.Interval -replace "PT" -replace "M"
118+
}
95119
}
96120
}
97-
121+
98122
return @{
99123
TaskName = $TaskName
100124
TaskPath = $TaskPath

0 commit comments

Comments
 (0)