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

[Question] How to specify day to run scheduled task? #59

Open
Zuldan opened this issue Mar 16, 2016 · 4 comments
Open

[Question] How to specify day to run scheduled task? #59

Zuldan opened this issue Mar 16, 2016 · 4 comments
Assignees
Labels

Comments

@Zuldan
Copy link

Zuldan commented Mar 16, 2016

Hi guitarrapc, any tips on how to configure a scheduled task to run for example every Saturday at 2AM?

I can't figure out how to specify what day to run the scheduled task on.

@guitarrapc
Copy link
Owner

Hi Zuldan,

Let's try set ScheduledAt as past date for Saturday AM2:00:00, like ScheduledAt = [DateTime]"2016/02/13 02:00:00". Then use RepetitionIntervalTimeSpanString as 1week, like RepetitionIntervalTimeSpanString = "7.00:00:00".

Code looks like this.

configuration Sample
{
    Import-DscResource -ModuleName GraniResource;
    cScheduleTask 1WeekSample
    {
        Ensure = "Present"
        TaskName = "Sample"
        TaskPath = "\"
        ScheduledAt = [DateTime]"2016/02/13 02:00:00" # Means Saturday
        RepetitionIntervalTimeSpanString = [TimeSpan]::FromDays(7).ToString() # run every week
        RepetitionDurationTimeSpanString = [TimeSpan]::MaxValue.ToString() # forever
        Execute = "powershell.exe"
        Argument = "-Command Get-Date"
        Disable = $true
        Hidden = $true
        Compatibility = "Win8"
        Runlevel = "Highest"
    }
}

Is it answer your question?

@guitarrapc guitarrapc self-assigned this Mar 16, 2016
@Zuldan
Copy link
Author

Zuldan commented Mar 16, 2016

Hi guitarrapc, I will play around with the code tomorrow and see how I go. Thank you for the fast response!

@Zuldan
Copy link
Author

Zuldan commented Mar 17, 2016

Hi guitarrapc,

After investigating it appears the resource is not creating a true 'Weekly' trigger. It's creating a 'One time'. Maybe you could add this functionality like so...

configuration Sample
{
Import-DscResource -ModuleName GraniResource;
cScheduleTask 1WeekSample
{
Ensure = "Present"
TaskName = "Sample"
TaskPath = ""
ScheduledAt = [DateTime]"02:00:00"
Weekly = $True
Day = 'Saturday'
Execute = "powershell.exe"
Argument = "-Command Get-Date"
Disable = $true
Hidden = $true
Compatibility = "Win8"
Runlevel = "Highest"
}
}

We're using this resource on 200+ servers and we need to change a current scheduled task from daily or weekly. I'm worried when admin's view the task settings and see "Run once" they might get confused.

On another note, have you considered contributing this resource to Microsoft? it's the best ScheduledTask DSC resource on the Internet and you already have all the Pester tests for it so I'm sure Microsoft would gladly accept it. Your code is beautiful!

@Zuldan
Copy link
Author

Zuldan commented Mar 28, 2016

Hi guittarpc, any chance of adding Day = to the options ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants