I want to automatically run a PowerCLI script every morning.
Note- This assumes….
- The script loads the Snapin-
- The script has the vCenter specified
- The service account has local access on the windows 2012 server to run a scheduled task.
- The server account is part of a vCenter role that has permission to read/make any changes.
Start / Run / taskschd.msc
- Right click on “Task Scheduler Library” on the left hand side.
- Click “Create Task”
- Fill in the name of the task. Ex. Daily Snapshot Email
- Fill in the description. Ex. Created/revised date and your name/email.
- Click “Change user or Group” to pick the service account.
- Check the box “Run whether user is logged on or not”.
- Pick time and then days.
Ex. I wanted this to run during the work week at 5am
(local time on the windows server I am creating this task on)
- I set “Stop task if it runs longer than” 3 hours.
(Note – I have yet to see this work)
- Program/Script is the path and file name to PowerShell
- Add arguments
-noprofile -NonInteractive -executionpolicy bypass -file
- Start in
d:scripts (location on the server where your .ps1 file is)
I did not change any settings since this is running on a server that is on 24/7/365 and not a laptop.
I set “Stop the task if it runs longer than” 4 hours. Again, I have yet to see this stop the task and end the powershell process.