Author Posts

November 3, 2017 at 8:46 pm

Hello my good folks,

Learning Powershell. I have been a db programmer and new to infrastructure programming.

I have a powershell script (say GetMetrics.ps1) . I can manually schedule this script as a task in windows job scheduler.
But I don't want to do this manually. I want to use powershell script to schedule this script as a task.

The reason being, we are bringing up an EC2 windows instance on AWS using cloudformation script. it works fine. Once that instance comes up I want to run a powershell script that can go and configure my GetMetrics.ps1 as a task on windows scheduler.

How can I do that? Are there any scripts available to do this?
Thanks and kind regards
jason

November 4, 2017 at 7:14 pm

Scheduled Task cmdlets were introduced with Server 2012. You need to do three things:

    Create a task action with New-ScheduledTaskAction
    Create a trigger for the task with New-ScheduledTaskTrigger
    Register the scheduled task with Register-ScheduledTask

Scripting Guy has a getting started guide.