Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScheduledTask: Delay Property Not Set for non-OnEvent Type Triggers #230

Closed
ShawnHardwick opened this issue Jul 9, 2019 · 3 comments · Fixed by #238
Closed

ScheduledTask: Delay Property Not Set for non-OnEvent Type Triggers #230

ShawnHardwick opened this issue Jul 9, 2019 · 3 comments · Fixed by #238
Labels
bug The issue is a bug. in progress The issue is being actively worked on by someone.

Comments

@ShawnHardwick
Copy link
Contributor

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

When using the delay property for any schedule type other than OnEvent, the property is never set in the scheduled task. This causes the test to always fail and the set to always run.

scheduletype = 'AtLogOn'
delay = '00:00:30'

Verbose logs showing the problem

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = Resourcetest,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName'
 = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer REDACTED with user sid SID REDACTED.
VERBOSE: [REDACTED]: LCM:  [ Start  Test     ]  [[ScheduledTask]DirectResourceAccess]
VERBOSE: [REDACTED]:                            [[ScheduledTask]DirectResourceAccess] Testing scheduled task 'OneDrive Mapper' in '\'.
VERBOSE: [REDACTED]:                            [[ScheduledTask]DirectResourceAccess] Getting scheduled task 'OneDrive Mapper' in '\'.
VERBOSE: [REDACTED]:                            [[ScheduledTask]DirectResourceAccess] Task 'OneDrive Mapper' found in '\'. Retrieving settings, first action, fi
rst trigger and repetition settings.
VERBOSE: [REDACTED]:                            [[ScheduledTask]DirectResourceAccess] Detected schedule type 'AtLogon' for first trigger.
VERBOSE: [REDACTED]:                            [[ScheduledTask]DirectResourceAccess] Current scheduled task values retrieved.
VERBOSE: [REDACTED]:                            [[ScheduledTask]DirectResourceAccess] Testing DSC parameter state.
VERBOSE: [REDACTED]:                            [[ScheduledTask]DirectResourceAccess]  TEST Verbose
VERBOSE: [REDACTED]:                            [[ScheduledTask]DirectResourceAccess]  MATCH: Value (type 'String') for property 'ActionExecutable' does
 match. Current state is 'C:\OneDrive_Mapper\OneDrive_Mapper.exe' and desired state is 'C:\OneDrive_Mapper\OneDrive_Mapper.exe'.
VERBOSE: [REDACTED]:                            [[ScheduledTask]DirectResourceAccess]  MATCH: Value (type 'String') for property 'LogonType' does match.
 Current state is 'ServiceAccount' and desired state is 'ServiceAccount'.
VERBOSE: [REDACTED]:                            [[ScheduledTask]DirectResourceAccess]  MATCH: Value (type 'String') for property 'TaskPath' does match. 
Current state is '\' and desired state is '\'.
VERBOSE: [REDACTED]:                            [[ScheduledTask]DirectResourceAccess]  MATCH: Value (type 'String') for property 'TaskName' does match. 
Current state is 'OneDrive Mapper' and desired state is 'OneDrive Mapper'.
VERBOSE: [REDACTED]:                            [[ScheduledTask]DirectResourceAccess]  MATCH: Value (type 'Boolean') for property 'Enable' does match. C
urrent state is 'True' and desired state is 'True'.
VERBOSE: [REDACTED]:                            [[ScheduledTask]DirectResourceAccess]  NOTMATCH: Value (type 'String') for property 'Delay' does not mat
ch. Current state is '00:00:00' and desired state is '00:00:30'.
VERBOSE: [REDACTED]:                            [[ScheduledTask]DirectResourceAccess]  MATCH: Value (type 'String') for property 'ScheduleType' does mat
ch. Current state is 'AtLogon' and desired state is 'AtLogOn'.
VERBOSE: [REDACTED]:                            [[ScheduledTask]DirectResourceAccess]  Test-DscParameter result is 'False'.
VERBOSE: [REDACTED]: LCM:  [ End    Test     ]  [[ScheduledTask]DirectResourceAccess] False in 0.8600 seconds.
VERBOSE: [REDACTED]: LCM:  [ End    Set      ]    in  0.9060 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.989 seconds

Suggested solution to the issue

Move the below line in the ScheduledTask resource in the Set-TargetResource cmdlet outside of the ScheduleType switch statement:
$trigger.Delay = [System.Xml.XmlConvert]::ToString([timespan]$Delay)

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

No configuration to provide

The operating system the target node is running

OsName               : Microsoft Windows Server 2016 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture       : 64-bit
WindowsBuildLabEx    : 14393.3053.amd64fre.rs1_release_inmarket.190612-1836
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running

PSVersion                      5.1.14393.3053                                                                                                                       
PSEdition                      Desktop                                                                                                                              
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                              
BuildVersion                   10.0.14393.3053                                                                                                                      
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)

6.4.0.0

@PlagueHO PlagueHO added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. labels Jul 10, 2019
@PlagueHO
Copy link
Member

Thanks for raising this @ShawnHardwick - looks like a straight forward fix. Happy to accept a PR or will try and get onto it this weekend.

@danielboth
Copy link
Member

Just moving the set of Delay out of OnEvent is a bit to simple unfortunately. This is because not all triggers support the delay property.

Supporting Delay:
AtLogon
AtStartUp
OnEvent

Not Supporting Delay:
Daily
Weekly
Once

Also, the delay property is only supported on W2016+ / W10+, mainly because the object returned by the tooling (New-ScheduledTaskTrigger) is different on W2012 / W8 (oh MS we love your consistency).

@PlagueHO PlagueHO added in progress The issue is being actively worked on by someone. and removed help wanted The issue is up for grabs for anyone in the community. labels Aug 8, 2019
@PlagueHO
Copy link
Member

PlagueHO commented Aug 8, 2019

I've been bitten by the differences in the Schedule objects on more than one occasion in this resource too. Thanks for submitting fix @danielboth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug. in progress The issue is being actively worked on by someone.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants