guitarrapc / GraniResource

PowerShell Desired State Configuration Resources for real production workload.
https://www.powershellgallery.com/packages/GraniResource
MIT License
44 stars 8 forks source link

Unable to create a new schedule task on non-existing or empty TaskPath #49

Closed renaudl closed 8 years ago

renaudl commented 8 years ago

Hello,

I have tested the scenario where a task is created on a taskpath that does not exists. The resource exit because it couldn't find a task with the same folder (I checked the code).

The problem is that this scenario is a 101 for DSC when you want to install a fresh new server. I have test the set resource function and it manages to create the task with a new folder. Why do you check existence of a taskpath then ?

Could you please help? ps: if an empty task folder exists in the scheduler it fails also.

guitarrapc commented 8 years ago

Hi, thank you for reporting issue. I could reproduce issue with following configuration.

configuration present
{
    Import-DscResource -Modulename GraniResource
    Node $AllNodes.Where{$_.Role -eq "localhost"}.NodeName
    {
        cScheduleTask fuga
        {
            Ensure = "present"
            Execute = "powershell.exe"
            Argument = '-Command "Get-Date | Out-File c:\hoge.log"'
            TaskName = "pityo"
            TaskPath = "\fuga\"
            ScheduledAt = [datetime]"00:00:00"
            Daily = $true
            Runlevel = "Highest"
            Disable = $false
        }
    }
}

$ConfigurationData = @{
    Allnodes = @(
    @{
        NodeName = "*"
        PSDscAllowPlainTextPassword = $true
    }
    @{
        NodeName ="localhost"
        Role = "localhost"
    }
    )
}
present -OutputPath . -ConfigurationData $ConfigurationData
Start-DscConfiguration -Wait -Force -Verbose -Path present -Debug

I will review and fix it.

guitarrapc commented 8 years ago

Hi, I have fix an issue and released ver.3.7.4.

You can get it from PowerShellGet or through GitHub.

Could you kindly try it?

renaudl commented 8 years ago

Sure, will test today. Thanks for the fix.

renaudl commented 8 years ago

Tested, It works. Thanks.

However, when pushing twice a configuration, it now seems to set the task each time meaning the test always return right. If nothing is changed, should it return false to avoid doing unnecessary actions?

guitarrapc commented 8 years ago

Thanks for test.

Sorry but I can't get what you mean.

However, when pushing twice a configuration, it now seems to set the task each time meaning the test always return right. If nothing is changed, should it return false to avoid doing unnecessary actions?

If you send same configuration for twice, resource will detect ScheduledTask is not changed and Test returns true to skip Set-TargetResource Action. You can see how it works with following confifugraiton.

configuration present
{
    Import-DscResource -Modulename GraniResource
    Node $AllNodes.Where{$_.Role -eq "localhost"}.NodeName
    {
        cScheduleTask hoge
        {
            Ensure = "Present"
            Execute = "powershell.exe"
            Argument = '-Command "Get-Date | Out-File c:\hoge.log"'
            TaskName = "hoge"
            TaskPath = "\hoge"
            ScheduledAt = [datetime]"00:00:00"
            RepetitionIntervalTimeSpanString = @(([TimeSpan]"01:00:00").ToString())
            RepetitionDurationTimeSpanString = @(([TimeSpan]::MaxValue).ToString())
            Compatibility = "Win8"
            Disable = $false
        }
    }
}

$ConfigurationData = @{
    Allnodes = @(
    @{
        NodeName = "*"
        PSDscAllowPlainTextPassword = $true
    }
    @{
        NodeName ="localhost"
        Role = "localhost"
    }
    )
}
present -OutputPath . -ConfigurationData $ConfigurationData
Start-DscConfiguration -Wait -Force -Verbose -Path present -Debug
renaudl commented 8 years ago

Look the traces

`PS C:\test\dsc> Start-DscConfiguration -debug -Verbose -wait -Path .\Config VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'cla ssName' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'. VERBOSE: An LCM method call arrived from computer LDDSC01 with user sid S-1-5-21-693817809-20915399-720130721-1400. VERBOSE: [LDDSC01]: LCM: [ Start Set ] VERBOSE: [LDDSC01]: LCM: [ Start Resource ] [[cScheduleTask]Task] VERBOSE: [LDDSC01]: LCM: [ Start Test ] [[cScheduleTask]Task] VERBOSE: [LDDSC01]: [[cScheduleTask]Task] False DEBUG: [LDDSC01]: [[cScheduleTask]Task] Checking TaskPath is exists with : rimes\ DEBUG: [LDDSC01]: [[cScheduleTask]Task] TaskPath : False () VERBOSE: [LDDSC01]: LCM: [ End Test ] [[cScheduleTask]Task] in 0.3120 seconds. VERBOSE: [LDDSC01]: LCM: [ Start Set ] [[cScheduleTask]Task] VERBOSE: [LDDSC01]: [[cScheduleTask]Task] Ensure detected as Present. Setting ScheduledTa sk for TaskPath 'rimes', TaskName 'TestRenaud2123'. DEBUG: [LDDSC01]: [[cScheduleTask]Task] Setting Action Execute : 'C:\Temp\test.bat', Argu ment : '', WorkingDirectory : ''. DEBUG: [LDDSC01]: [[cScheduleTask]Task] Setting Trigger RepetitionIntervalTimeSpanString : '00:05:00', RepetitionDurationTimeSpanString : '10675199.02:48:05.4775807', ScheduledAt : 'System.DateTime[]', Dai ly : 'False', Once : 'False'. DEBUG: [LDDSC01]: [[cScheduleTask]Task] Skip Credential. Using System for Principal. DEBUG: [LDDSC01]: [[cScheduleTask]Task]

State : Ready Actions : {MSFT_TaskExecAction} Author : Date : Description : Documentation : Principal : MSFT_TaskPrincipal2 SecurityDescriptor : Settings : MSFT_TaskSettings3 Source : TaskName : TestRenaud2123 TaskPath : \rimes\ Triggers : {MSFT_TaskTimeTrigger} URI : Version : PSComputerName : CimClass : Root/Microsoft/Windows/TaskScheduler:MSFT_ScheduledTask CimInstanceProperties : {Actions, Author, Date, Description...} CimSystemProperties : Microsoft.Management.Infrastructure.CimSystemProperties VERBOSE: [LDDSC01]: LCM: [ End Set ] [[cScheduleTask]Task] in 0.9070 seconds. VERBOSE: [LDDSC01]: LCM: [ End Resource ] [[cScheduleTask]Task] VERBOSE: [LDDSC01]: LCM: [ End Set ] VERBOSE: [LDDSC01]: LCM: [ End Set ] in 1.3120 seconds. VERBOSE: Operation 'Invoke CimMethod' complete. VERBOSE: Time taken for configuration job to complete is 1.326 seconds

PS C:\test\dsc> Start-DscConfiguration -debug -Verbose -wait -Path .\Config VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'cla ssName' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'. VERBOSE: An LCM method call arrived from computer LDDSC01 with user sid S-1-5-21-693817809-20915399-720130721-1400. VERBOSE: [LDDSC01]: LCM: [ Start Set ] VERBOSE: [LDDSC01]: LCM: [ Start Resource ] [[cScheduleTask]Task] VERBOSE: [LDDSC01]: LCM: [ Start Test ] [[cScheduleTask]Task] VERBOSE: [LDDSC01]: [[cScheduleTask]Task] False DEBUG: [LDDSC01]: [[cScheduleTask]Task] Checking TaskPath is exists with : rimes\ DEBUG: [LDDSC01]: [[cScheduleTask]Task] TaskPath : False () VERBOSE: [LDDSC01]: LCM: [ End Test ] [[cScheduleTask]Task] in 0.2970 seconds. VERBOSE: [LDDSC01]: LCM: [ Start Set ] [[cScheduleTask]Task] VERBOSE: [LDDSC01]: [[cScheduleTask]Task] Ensure detected as Present. Setting ScheduledTa sk for TaskPath 'rimes', TaskName 'TestRenaud2123'. DEBUG: [LDDSC01]: [[cScheduleTask]Task] Setting Action Execute : 'C:\Temp\test.bat', Argu ment : '', WorkingDirectory : ''. DEBUG: [LDDSC01]: [[cScheduleTask]Task] Setting Trigger RepetitionIntervalTimeSpanString : '00:05:00', RepetitionDurationTimeSpanString : '10675199.02:48:05.4775807', ScheduledAt : 'System.DateTime[]', Dai ly : 'False', Once : 'False'. DEBUG: [LDDSC01]: [[cScheduleTask]Task] Skip Credential. Using System for Principal. DEBUG: [LDDSC01]: [[cScheduleTask]Task]

State : Ready Actions : {MSFT_TaskExecAction} Author : Date : Description : Documentation : Principal : MSFT_TaskPrincipal2 SecurityDescriptor : Settings : MSFT_TaskSettings3 Source : TaskName : TestRenaud2123 TaskPath : \rimes\ Triggers : {MSFT_TaskTimeTrigger} URI : Version : PSComputerName : CimClass : Root/Microsoft/Windows/TaskScheduler:MSFT_ScheduledTask CimInstanceProperties : {Actions, Author, Date, Description...} CimSystemProperties : Microsoft.Management.Infrastructure.CimSystemProperties VERBOSE: [LDDSC01]: LCM: [ End Set ] [[cScheduleTask]Task] in 0.5940 seconds. VERBOSE: [LDDSC01]: LCM: [ End Resource ] [[cScheduleTask]Task] VERBOSE: [LDDSC01]: LCM: [ End Set ] VERBOSE: [LDDSC01]: LCM: [ End Set ] in 1.0000 seconds. VERBOSE: Operation 'Invoke CimMethod' complete. VERBOSE: Time taken for configuration job to complete is 1.016 seconds`

In the second run, it seems to set the action and other things. Is that doing it or is it just misleading traces?

guitarrapc commented 8 years ago

Thanks for trace log. It seems odd, very strange. I want to reproduce issue on my lab.

First of all, did you omit Test message? When I ran same configuration on my lab, it shows like following.

Test1

Scratch environment to run

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'
className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration
'.
VERBOSE: An LCM method call arrived from computer DSCSERVER with user sid S-1-5-21-664902234-602511844-991937109-
500.
VERBOSE: [DSCSERVER]: LCM:  [ Start  Set      ]
VERBOSE: [DSCSERVER]: LCM:  [ Start  Resource ]  [[cScheduleTask]hoge]
VERBOSE: [DSCSERVER]: LCM:  [ Start  Test     ]  [[cScheduleTask]hoge]
VERBOSE: [DSCSERVER]:                            [[cScheduleTask]hoge] False
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Checking TaskPath is exists with : \hoge\
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] TaskPath : False ()
VERBOSE: [DSCSERVER]: LCM:  [ End    Test     ]  [[cScheduleTask]hoge]  in 0.6870 seconds.
VERBOSE: [DSCSERVER]: LCM:  [ Start  Set      ]  [[cScheduleTask]hoge]
VERBOSE: [DSCSERVER]:                            [[cScheduleTask]hoge] Ensure detected as Present. Setting Schedu
ledTask for TaskPath '\hoge', TaskName 'hoge'.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Setting Action Execute : 'powershell.exe', A
rgument : '-Command "Get-Date | Out-File c:\hoge.log"', WorkingDirectory : ''.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Setting Trigger RepetitionIntervalTimeSpanSt
ring : '01:00:00', RepetitionDurationTimeSpanString : '10675199.02:48:05.4775807', ScheduledAt : 'System.DateTime
[]', Daily : 'False', Once : 'False'.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skip Credential. Using System for Principal.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] 

State                 : Ready
Actions               : {MSFT_TaskExecAction}
Author                : 
Date                  : 
Description           : 
Documentation         : 
Principal             : MSFT_TaskPrincipal2
SecurityDescriptor    : 
Settings              : MSFT_TaskSettings3
Source                : 
TaskName              : hoge
TaskPath              : \hoge\
Triggers              : {MSFT_TaskTimeTrigger}
URI                   : 
Version               : 
PSComputerName        : 
CimClass              : Root/Microsoft/Windows/TaskScheduler:MSFT_ScheduledTask
CimInstanceProperties : {Actions, Author, Date, Description...}
CimSystemProperties   : Microsoft.Management.Infrastructure.CimSystemProperties
VERBOSE: [DSCSERVER]: LCM:  [ End    Set      ]  [[cScheduleTask]hoge]  in 0.5780 seconds.
VERBOSE: [DSCSERVER]: LCM:  [ End    Resource ]  [[cScheduleTask]hoge]
VERBOSE: [DSCSERVER]: LCM:  [ End    Set      ]    in  1.6390 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 1.361 seconds

2nd Ran right after same configuration was done

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'
className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration
'.
VERBOSE: An LCM method call arrived from computer DSCSERVER with user sid S-1-5-21-664902234-602511844-991937109-
500.
VERBOSE: [DSCSERVER]: LCM:  [ Start  Set      ]
VERBOSE: [DSCSERVER]: LCM:  [ Start  Resource ]  [[cScheduleTask]hoge]
VERBOSE: [DSCSERVER]: LCM:  [ Start  Test     ]  [[cScheduleTask]hoge]
VERBOSE: [DSCSERVER]:                            [[cScheduleTask]hoge] False
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Checking TaskPath is exists with : \hoge\
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] TaskPath : True (\hoge\)
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Checking Taskname is exists with : hoge
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Taskname : True (hoge)
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping Description as value not passed to 
function.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Checking Execute is match with : powershell.
exe
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Execute : True (powershell.exe)
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Checking Arguments is match with : -Command 
"Get-Date | Out-File c:\hoge.log"
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Arguments : True (-Command "Get-Date | Out-F
ile c:\hoge.log")
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping WorkingDirectory as value not passe
d to function.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping UserId as value not passed to funct
ion.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping RunLevel as value not passed to fun
ction.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Checking Compatibility is match with : Win8
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Compatibility : True (Win8)
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping ExecutionTimeLimit as value not pas
sed to function.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping Hidden as value not passed to funct
ion.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Checking Disable is match with : False
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Disable : True (False)
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Checking StartBoundary is match with : 2016/
02/02 0:00:00
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] StartBoundary : True (2016/02/02 0:00:00)
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Checking Interval is match with : 01:00:00
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Interval : True (60)
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping Daily as value not passed to functi
on.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping Once as value not passed to functio
n.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping AtStatup as value not passed to fun
ction.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping AtLogOn as value not passed to func
tion.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping UserId as value not passed to funct
ion.
VERBOSE: [DSCSERVER]: LCM:  [ End    Test     ]  [[cScheduleTask]hoge]  in 0.5620 seconds.
VERBOSE: [DSCSERVER]: LCM:  [ Skip   Set      ]  [[cScheduleTask]hoge]
VERBOSE: [DSCSERVER]: LCM:  [ End    Resource ]  [[cScheduleTask]hoge]
VERBOSE: [DSCSERVER]: LCM:  [ End    Set      ]    in  0.7597 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.885 seconds

Test2

Looking into your trace message, is configuration you test was like this?

configuration present
{
    Import-DscResource -Modulename GraniResource
    Node $AllNodes.Where{$_.Role -eq "localhost"}.NodeName
    {
        cScheduleTask hoge
        {
            Ensure = "Present"
            Execute = "C:\Temp\test.bat"
            TaskName = "TestRenaud2123"
            TaskPath = "\rimes"
            ScheduledAt = [datetime]"00:00:00"
            RepetitionIntervalTimeSpanString = @(([TimeSpan]"00:05:00").ToString())
            RepetitionDurationTimeSpanString = @(([TimeSpan]::MaxValue).ToString())
            Disable = $false
        }
    }
}

$ConfigurationData = @{
    Allnodes = @(
    @{
        NodeName = "*"
        PSDscAllowPlainTextPassword = $true
    }
    @{
        NodeName ="localhost"
        Role = "localhost"
    }
    )
}
present -OutputPath . -ConfigurationData $ConfigurationData
Start-DscConfiguration -Wait -Force -Verbose -Path present -Debug

Then test result was as below.

Scratch Environment

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'
className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration
'.
VERBOSE: An LCM method call arrived from computer DSCSERVER with user sid S-1-5-21-664902234-602511844-991937109-
500.
VERBOSE: [DSCSERVER]: LCM:  [ Start  Set      ]
VERBOSE: [DSCSERVER]: LCM:  [ Start  Resource ]  [[cScheduleTask]hoge]
VERBOSE: [DSCSERVER]: LCM:  [ Start  Test     ]  [[cScheduleTask]hoge]
VERBOSE: [DSCSERVER]:                            [[cScheduleTask]hoge] False
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Checking TaskPath is exists with : \rimes\
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] TaskPath : False ()
VERBOSE: [DSCSERVER]: LCM:  [ End    Test     ]  [[cScheduleTask]hoge]  in 0.3900 seconds.
VERBOSE: [DSCSERVER]: LCM:  [ Start  Set      ]  [[cScheduleTask]hoge]
VERBOSE: [DSCSERVER]:                            [[cScheduleTask]hoge] Ensure detected as Present. Setting Schedu
ledTask for TaskPath '\rimes', TaskName 'TestRenaud2123'.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Setting Action Execute : 'C:\Temp\test.bat',
 Argument : '', WorkingDirectory : ''.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Setting Trigger RepetitionIntervalTimeSpanSt
ring : '00:05:00', RepetitionDurationTimeSpanString : '10675199.02:48:05.4775807', ScheduledAt : 'System.DateTime
[]', Daily : 'False', Once : 'False'.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skip Credential. Using System for Principal.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] 

State                 : Ready
Actions               : {MSFT_TaskExecAction}
Author                : 
Date                  : 
Description           : 
Documentation         : 
Principal             : MSFT_TaskPrincipal2
SecurityDescriptor    : 
Settings              : MSFT_TaskSettings3
Source                : 
TaskName              : TestRenaud2123
TaskPath              : \rimes\
Triggers              : {MSFT_TaskTimeTrigger}
URI                   : 
Version               : 
PSComputerName        : 
CimClass              : Root/Microsoft/Windows/TaskScheduler:MSFT_ScheduledTask
CimInstanceProperties : {Actions, Author, Date, Description...}
CimSystemProperties   : Microsoft.Management.Infrastructure.CimSystemProperties
VERBOSE: [DSCSERVER]: LCM:  [ End    Set      ]  [[cScheduleTask]hoge]  in 0.5000 seconds.
VERBOSE: [DSCSERVER]: LCM:  [ End    Resource ]  [[cScheduleTask]hoge]
VERBOSE: [DSCSERVER]: LCM:  [ End    Set      ]    in  1.1555 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.967 seconds

2nd Ran right after same configuration was done

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'
className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration
'.
VERBOSE: An LCM method call arrived from computer DSCSERVER with user sid S-1-5-21-664902234-602511844-991937109-
500.
VERBOSE: [DSCSERVER]: LCM:  [ Start  Set      ]
VERBOSE: [DSCSERVER]: LCM:  [ Start  Resource ]  [[cScheduleTask]hoge]
VERBOSE: [DSCSERVER]: LCM:  [ Start  Test     ]  [[cScheduleTask]hoge]
VERBOSE: [DSCSERVER]:                            [[cScheduleTask]hoge] False
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Checking TaskPath is exists with : \rimes\
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] TaskPath : True (\rimes\)
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Checking Taskname is exists with : TestRenau
d2123
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Taskname : True (TestRenaud2123)
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping Description as value not passed to 
function.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Checking Execute is match with : C:\Temp\tes
t.bat
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Execute : True (C:\Temp\test.bat)
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping Arguments as value not passed to fu
nction.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping WorkingDirectory as value not passe
d to function.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping UserId as value not passed to funct
ion.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping RunLevel as value not passed to fun
ction.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping Compatibility as value not passed t
o function.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping ExecutionTimeLimit as value not pas
sed to function.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping Hidden as value not passed to funct
ion.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Checking Disable is match with : False
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Disable : True (False)
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Checking StartBoundary is match with : 2016/
02/02 0:00:00
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] StartBoundary : True (2016/02/02 0:00:00)
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Checking Interval is match with : 00:05:00
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Interval : True (5)
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping Daily as value not passed to functi
on.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping Once as value not passed to functio
n.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping AtStatup as value not passed to fun
ction.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping AtLogOn as value not passed to func
tion.
DEBUG: [DSCSERVER]:                            [[cScheduleTask]hoge] Skipping UserId as value not passed to funct
ion.
VERBOSE: [DSCSERVER]: LCM:  [ End    Test     ]  [[cScheduleTask]hoge]  in 0.4220 seconds.
VERBOSE: [DSCSERVER]: LCM:  [ Skip   Set      ]  [[cScheduleTask]hoge]
VERBOSE: [DSCSERVER]: LCM:  [ End    Resource ]  [[cScheduleTask]hoge]
VERBOSE: [DSCSERVER]: LCM:  [ End    Set      ]    in  0.5804 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.637 seconds

Can you share a configuration you tried? Also I have noticed error when you set multiple ScheduledAt like below.

configuration present
{
    Import-DscResource -Modulename GraniResource
    Node $AllNodes.Where{$_.Role -eq "localhost"}.NodeName
    {
        cScheduleTask hoge
        {
            Ensure = "Present"
            Execute = "C:\Temp\test.bat"
            TaskName = "TestRenaud2123"
            TaskPath = "\rimes"
            ScheduledAt = [datetime]"00:00:00", [datetime]"01:00:00"
            RepetitionIntervalTimeSpanString = @(([TimeSpan]"00:05:00").ToString())
            RepetitionDurationTimeSpanString = @(([TimeSpan]::MaxValue).ToString())
            Disable = $false
        }
    }
}
renaudl commented 8 years ago

Hi, I found the root cause. My Task path was “rimes”, when setting “/rimes” I works fine.

So “rimes” alone allows to create but then always reinstall as it compares to “/rimes/”.

I have changed my config. It may be worth to had a comment somewhere.

Kind regards

renaud

From: Ikiru Yoshizaki [mailto:notifications@github.com] Sent: mardi 2 février 2016 14:11 To: guitarrapc/DSCResources Cc: Renaud Larzilliere Subject: Re: [DSCResources] Unable to create a new schedule task on non-existing or empty TaskPath (#49)

It's odd, very strange. Do you omit Test message?When I ran same configuration on my lab, it shows like this.

Test1 Scratch environment to run

Mode LastWriteTime Length Name


-a--- 2/2/2016 10:02 PM 1780 localhost.mof

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'

className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration

'.

VERBOSE: An LCM method call arrived from computer DSCSERVER with user sid S-1-5-21-664902234-602511844-991937109-

500.

VERBOSE: [DSCSERVER]: LCM: [ Start Set ]

VERBOSE: [DSCSERVER]: LCM: [ Start Resource ] [[cScheduleTask]hoge]

VERBOSE: [DSCSERVER]: LCM: [ Start Test ] [[cScheduleTask]hoge]

VERBOSE: [DSCSERVER]: [[cScheduleTask]hoge] False

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Checking TaskPath is exists with : \hoge\

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] TaskPath : False ()

VERBOSE: [DSCSERVER]: LCM: [ End Test ] [[cScheduleTask]hoge] in 0.6870 seconds.

VERBOSE: [DSCSERVER]: LCM: [ Start Set ] [[cScheduleTask]hoge]

VERBOSE: [DSCSERVER]: [[cScheduleTask]hoge] Ensure detected as Present. Setting Schedu

ledTask for TaskPath '\hoge', TaskName 'hoge'.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Setting Action Execute : 'powershell.exe', A

rgument : '-Command "Get-Date | Out-File c:\hoge.log"', WorkingDirectory : ''.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Setting Trigger RepetitionIntervalTimeSpanSt

ring : '01:00:00', RepetitionDurationTimeSpanString : '10675199.02:48:05.4775807', ScheduledAt : 'System.DateTime

[]', Daily : 'False', Once : 'False'.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skip Credential. Using System for Principal.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge]

State : Ready

Actions : {MSFT_TaskExecAction}

Author :

Date :

Description :

Documentation :

Principal : MSFT_TaskPrincipal2

SecurityDescriptor :

Settings : MSFT_TaskSettings3

Source :

TaskName : hoge

TaskPath : \hoge\

Triggers : {MSFT_TaskTimeTrigger}

URI :

Version :

PSComputerName :

CimClass : Root/Microsoft/Windows/TaskScheduler:MSFT_ScheduledTask

CimInstanceProperties : {Actions, Author, Date, Description...}

CimSystemProperties : Microsoft.Management.Infrastructure.CimSystemProperties

VERBOSE: [DSCSERVER]: LCM: [ End Set ] [[cScheduleTask]hoge] in 0.5780 seconds.

VERBOSE: [DSCSERVER]: LCM: [ End Resource ] [[cScheduleTask]hoge]

VERBOSE: [DSCSERVER]: LCM: [ End Set ] in 1.6390 seconds.

VERBOSE: Operation 'Invoke CimMethod' complete.

VERBOSE: Time taken for configuration job to complete is 1.361 seconds

2nd Ran right after same configuration was done

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'

className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration

'.

VERBOSE: An LCM method call arrived from computer DSCSERVER with user sid S-1-5-21-664902234-602511844-991937109-

500.

VERBOSE: [DSCSERVER]: LCM: [ Start Set ]

VERBOSE: [DSCSERVER]: LCM: [ Start Resource ] [[cScheduleTask]hoge]

VERBOSE: [DSCSERVER]: LCM: [ Start Test ] [[cScheduleTask]hoge]

VERBOSE: [DSCSERVER]: [[cScheduleTask]hoge] False

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Checking TaskPath is exists with : \hoge\

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] TaskPath : True (\hoge)

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Checking Taskname is exists with : hoge

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Taskname : True (hoge)

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping Description as value not passed to

function.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Checking Execute is match with : powershell.

exe

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Execute : True (powershell.exe)

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Checking Arguments is match with : -Command

"Get-Date | Out-File c:\hoge.log"

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Arguments : True (-Command "Get-Date | Out-F

ile c:\hoge.log")

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping WorkingDirectory as value not passe

d to function.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping UserId as value not passed to funct

ion.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping RunLevel as value not passed to fun

ction.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Checking Compatibility is match with : Win8

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Compatibility : True (Win8)

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping ExecutionTimeLimit as value not pas

sed to function.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping Hidden as value not passed to funct

ion.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Checking Disable is match with : False

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Disable : True (False)

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Checking StartBoundary is match with : 2016/

02/02 0:00:00

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] StartBoundary : True (2016/02/02 0:00:00)

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Checking Interval is match with : 01:00:00

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Interval : True (60)

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping Daily as value not passed to functi

on.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping Once as value not passed to functio

n.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping AtStatup as value not passed to fun

ction.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping AtLogOn as value not passed to func

tion.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping UserId as value not passed to funct

ion.

VERBOSE: [DSCSERVER]: LCM: [ End Test ] [[cScheduleTask]hoge] in 0.5620 seconds.

VERBOSE: [DSCSERVER]: LCM: [ Skip Set ] [[cScheduleTask]hoge]

VERBOSE: [DSCSERVER]: LCM: [ End Resource ] [[cScheduleTask]hoge]

VERBOSE: [DSCSERVER]: LCM: [ End Set ] in 0.7597 seconds.

VERBOSE: Operation 'Invoke CimMethod' complete.

VERBOSE: Time taken for configuration job to complete is 0.885 seconds

Test2

Looking into your trace message, is configuration you test was like this?

configuration present

{

Import-DscResource -Modulename GraniResource

Node $AllNodes.Where{$_.Role -eq "localhost"}.NodeName

{

    cScheduleTask hoge

    {

        Ensure = "Present"

        Execute = "C:\Temp\test.bat"

        TaskName = "TestRenaud2123"

        TaskPath = "\rimes"

        ScheduledAt = [datetime]"00:00:00"

        RepetitionIntervalTimeSpanString = @(([TimeSpan]"00:05:00").ToString())

        RepetitionDurationTimeSpanString = @(([TimeSpan]::MaxValue).ToString())

        Disable = $false

    }

}

}

$ConfigurationData = @{

Allnodes = @(

@{

    NodeName = "*"

    PSDscAllowPlainTextPassword = $true

}

@{

    NodeName ="localhost"

    Role = "localhost"

}

)

}

present -OutputPath . -ConfigurationData $ConfigurationData

Start-DscConfiguration -Wait -Force -Verbose -Path present -Debug

Then test result was as below.

Scratch Environment

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'

className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration

'.

VERBOSE: An LCM method call arrived from computer DSCSERVER with user sid S-1-5-21-664902234-602511844-991937109-

500.

VERBOSE: [DSCSERVER]: LCM: [ Start Set ]

VERBOSE: [DSCSERVER]: LCM: [ Start Resource ] [[cScheduleTask]hoge]

VERBOSE: [DSCSERVER]: LCM: [ Start Test ] [[cScheduleTask]hoge]

VERBOSE: [DSCSERVER]: [[cScheduleTask]hoge] False

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Checking TaskPath is exists with : \rimes\

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] TaskPath : False ()

VERBOSE: [DSCSERVER]: LCM: [ End Test ] [[cScheduleTask]hoge] in 0.3900 seconds.

VERBOSE: [DSCSERVER]: LCM: [ Start Set ] [[cScheduleTask]hoge]

VERBOSE: [DSCSERVER]: [[cScheduleTask]hoge] Ensure detected as Present. Setting Schedu

ledTask for TaskPath '\rimes', TaskName 'TestRenaud2123'.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Setting Action Execute : 'C:\Temp\test.bat',

Argument : '', WorkingDirectory : ''.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Setting Trigger RepetitionIntervalTimeSpanSt

ring : '00:05:00', RepetitionDurationTimeSpanString : '10675199.02:48:05.4775807', ScheduledAt : 'System.DateTime

[]', Daily : 'False', Once : 'False'.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skip Credential. Using System for Principal.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge]

State : Ready

Actions : {MSFT_TaskExecAction}

Author :

Date :

Description :

Documentation :

Principal : MSFT_TaskPrincipal2

SecurityDescriptor :

Settings : MSFT_TaskSettings3

Source :

TaskName : TestRenaud2123

TaskPath : \rimes\

Triggers : {MSFT_TaskTimeTrigger}

URI :

Version :

PSComputerName :

CimClass : Root/Microsoft/Windows/TaskScheduler:MSFT_ScheduledTask

CimInstanceProperties : {Actions, Author, Date, Description...}

CimSystemProperties : Microsoft.Management.Infrastructure.CimSystemProperties

VERBOSE: [DSCSERVER]: LCM: [ End Set ] [[cScheduleTask]hoge] in 0.5000 seconds.

VERBOSE: [DSCSERVER]: LCM: [ End Resource ] [[cScheduleTask]hoge]

VERBOSE: [DSCSERVER]: LCM: [ End Set ] in 1.1555 seconds.

VERBOSE: Operation 'Invoke CimMethod' complete.

VERBOSE: Time taken for configuration job to complete is 0.967 seconds

2nd Ran right after same configuration was done

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'

className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration

'.

VERBOSE: An LCM method call arrived from computer DSCSERVER with user sid S-1-5-21-664902234-602511844-991937109-

500.

VERBOSE: [DSCSERVER]: LCM: [ Start Set ]

VERBOSE: [DSCSERVER]: LCM: [ Start Resource ] [[cScheduleTask]hoge]

VERBOSE: [DSCSERVER]: LCM: [ Start Test ] [[cScheduleTask]hoge]

VERBOSE: [DSCSERVER]: [[cScheduleTask]hoge] False

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Checking TaskPath is exists with : \rimes\

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] TaskPath : True (\rimes)

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Checking Taskname is exists with : TestRenau

d2123

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Taskname : True (TestRenaud2123)

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping Description as value not passed to

function.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Checking Execute is match with : C:\Temp\tes

t.bat

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Execute : True (C:\Temp\test.bat)

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping Arguments as value not passed to fu

nction.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping WorkingDirectory as value not passe

d to function.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping UserId as value not passed to funct

ion.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping RunLevel as value not passed to fun

ction.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping Compatibility as value not passed t

o function.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping ExecutionTimeLimit as value not pas

sed to function.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping Hidden as value not passed to funct

ion.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Checking Disable is match with : False

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Disable : True (False)

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Checking StartBoundary is match with : 2016/

02/02 0:00:00

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] StartBoundary : True (2016/02/02 0:00:00)

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Checking Interval is match with : 00:05:00

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Interval : True (5)

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping Daily as value not passed to functi

on.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping Once as value not passed to functio

n.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping AtStatup as value not passed to fun

ction.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping AtLogOn as value not passed to func

tion.

DEBUG: [DSCSERVER]: [[cScheduleTask]hoge] Skipping UserId as value not passed to funct

ion.

VERBOSE: [DSCSERVER]: LCM: [ End Test ] [[cScheduleTask]hoge] in 0.4220 seconds.

VERBOSE: [DSCSERVER]: LCM: [ Skip Set ] [[cScheduleTask]hoge]

VERBOSE: [DSCSERVER]: LCM: [ End Resource ] [[cScheduleTask]hoge]

VERBOSE: [DSCSERVER]: LCM: [ End Set ] in 0.5804 seconds.

VERBOSE: Operation 'Invoke CimMethod' complete.

VERBOSE: Time taken for configuration job to complete is 0.637 seconds

Can you share a configuration you tried? Also I have noticed error when you set multiple ScheduledAt like below.

configuration present

{

Import-DscResource -Modulename GraniResource

Node $AllNodes.Where{$_.Role -eq "localhost"}.NodeName

{

    cScheduleTask hoge

    {

        Ensure = "Present"

        Execute = "C:\Temp\test.bat"

        TaskName = "TestRenaud2123"

        TaskPath = "\rimes"

        ScheduledAt = [datetime]"00:00:00", [datetime]"01:00:00"

        RepetitionIntervalTimeSpanString = @(([TimeSpan]"00:05:00").ToString())

        RepetitionDurationTimeSpanString = @(([TimeSpan]::MaxValue).ToString())

        Disable = $false

    }

}

}

$ConfigurationData = @{

Allnodes = @(

@{

    NodeName = "*"

    PSDscAllowPlainTextPassword = $true

}

@{

    NodeName ="localhost"

    Role = "localhost"

}

)

}

present -OutputPath . -ConfigurationData $ConfigurationData

Start-DscConfiguration -Wait -Force -Verbose -Path present -Debug

Reply to this email directly or view it on GitHubhttps://github.com/guitarrapc/DSCResources/issues/49#issuecomment-178569998.

This email has been scanned for email related threats and delivered safely by Mimecast.

For more information please visit http://www.mimecast.com

guitarrapc commented 8 years ago

Hi Renaudi, That's great feed back. Thanks a lot!

I have already add helper for "LastChar" but not yet for "FirstChar". I will review and support it on next version.

Cheers,

renaudl commented 8 years ago

Hi Ikiru

That was a pleasure.

Kind regards

Renaud

From: Ikiru Yoshizaki [mailto:notifications@github.com] Sent: mardi 2 février 2016 14:21 To: guitarrapc/DSCResources Cc: Renaud Larzilliere Subject: Re: [DSCResources] Unable to create a new schedule task on non-existing or empty TaskPath (#49)

Hi Renaudi, That's great feed back. Thanks a lot!

I have already add helper for "LastChar" but not yet for "FirstChar". I will review and support it on next version.

Cheers,

Reply to this email directly or view it on GitHubhttps://github.com/guitarrapc/DSCResources/issues/49#issuecomment-178571971.

This email has been scanned for email related threats and delivered safely by Mimecast.

For more information please visit http://www.mimecast.com