Powershell script to schedule a poweshell script on a windows 2012 server

This topic contains 1 reply, has 2 voices, and was last updated by  Matt Bloomfield 1 week, 6 days ago.

  • Author
    Posts
  • #83611

    jason smith
    Participant

    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

  • #83632

    Matt Bloomfield
    Participant

    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.

You must be logged in to reply to this topic.