ComputerManagementDsc icon indicating copy to clipboard operation
ComputerManagementDsc copied to clipboard

ScheduledTask - DaysOfWeek array ordering causing config drift

Open dappleby300 opened this issue 5 years ago • 0 comments

Details of the scenario you tried and the problem that is occurring

When creating a ScheduledTask using DaysOfWeek if the array ordering is not correct the configuration constantly drifts

It seems the array order must match the enum ordering in the code. This issue maybe addressed with just a note in the documentation.

Verbose logs showing the problem

VERBOSE: [SERVER-FS1]:                            [[ScheduledTask]TestSH::[profile_win2019]profile_win2019] Comparing values in property 'DaysOfWeek'. (DRC0028)
VERBOSE: [SERVER-FS1]:                            [[ScheduledTask]TestSH::[profile_win2019]profile_win2019] NOTMATCH: Value [0] (type 'System.String') for property 'DaysOfWeek' does match. Current state is 'Sunday' and desired state is 'Monday'. (DRC0024)
VERBOSE: [SERVER-FS1]:                            [[ScheduledTask]TestSH::[profile_win2019]profile_win2019] NOTMATCH: Value [1] (type 'System.String') for property 'DaysOfWeek' does match. Current state is 'Monday' and desired state is 'Tuesday'. (DRC0024)
VERBOSE: [SERVER-FS1]:                            [[ScheduledTask]TestSH::[profile_win2019]profile_win2019] NOTMATCH: Value [2] (type 'System.String') for property 'DaysOfWeek' does match. Current state is 'Tuesday' and desired state is 'Wednesday'. (DRC0024)
VERBOSE: [SERVER-FS1]:                            [[ScheduledTask]TestSH::[profile_win2019]profile_win2019] NOTMATCH: Value [3] (type 'System.String') for property 'DaysOfWeek' does match. Current state is 'Wednesday' and desired state is 'Thursday'. (DRC0024)
VERBOSE: [SERVER-FS1]:                            [[ScheduledTask]TestSH::[profile_win2019]profile_win2019] NOTMATCH: Value [4] (type 'System.String') for property 'DaysOfWeek' does match. Current state is 'Thursday' and desired state is 'Friday'. (DRC0024)
VERBOSE: [SERVER-FS1]:                            [[ScheduledTask]TestSH::[profile_win2019]profile_win2019] NOTMATCH: Value [5] (type 'System.String') for property 'DaysOfWeek' does match. Current state is 'Friday' and desired state is 'Sunday'. (DRC0024)

Suggested solution to the issue

Simply adjusting the ordering of the DaysOfWeek in the configuration fixes this issue.

ScheduledTask 'TestSH'
    {
        Ensure                  = 'Present'
        TaskName                = 'TestSH'
        TaskPath                = $Node.ScheduledTaskBasePath
        Description             = 'Test'
        ActionExecutable        = 'c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
        ActionArguments         = '-NonInteractive -File C:\scripts\testing\testscript.ps1'
        ActionWorkingPath       = 'C:\scripts\testing'
        ScheduleType            = 'Weekly'
        WeeksInterval           = 1
        DaysOfWeek              = @('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday')
        StartTime               = '2020-01-01 14:00:02'
        ExecutionTimeLimit      = '0.12:00:00'
        MultipleInstances       = 'IgnoreNew'
        Priority                = 9
        Compatibility           = 'Win8'
    }

The DSC configuration that is used to reproduce the issue (as detailed as possible)

ScheduledTask 'TestSH'
    {
        Ensure                  = 'Present'
        TaskName                = 'TestSH'
        TaskPath                = $Node.ScheduledTaskBasePath
        Description             = 'Test'
        ActionExecutable        = 'c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
        ActionArguments         = '-NonInteractive -File C:\scripts\testing\testscript.ps1'
        ActionWorkingPath       = 'C:\scripts\testing'
        ScheduleType            = 'Weekly'
        WeeksInterval           = 1
        DaysOfWeek              = @('Monday','Tuesday','Wednesday','Thursday','Friday','Sunday')
        StartTime               = '2020-01-01 14:00:02'
        ExecutionTimeLimit      = '0.12:00:00'
        MultipleInstances       = 'IgnoreNew'
        Priority                = 9
        Compatibility           = 'Win8'
    }

The operating system the target node is running

OsName               : Microsoft Windows Server 2019 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1809
WindowsBuildLabEx    : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running

Name                           Value
----                           -----
PSVersion                      5.1.17763.1490
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.1490
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

ComputerManagementDSC 8.4.0

dappleby300 avatar Jan 13 '21 04:01 dappleby300