To run an AppAssure PowerShell script as a scheduled task please do the following:
1. Create a folder to host the AppAssure Powershell script. The best practice is to prefix the folder with "AA" and to indicate the type of job the task needs to execute. For instance, if the job to be run is creating a report, the folder may be called:
Please avoid empty spaces in the folder name as it may be difficult to work around them.
2. Copy the Powershell script (i.e. MyReport.ps1) in the folder. Make sure that it is not blocked; if you downloaded it from the internet it may be (right-click->properties->unblock).
3. Create an empty .bat file in the same folder. Call it same as the folder, for instance, in this case AAReport0.bat
4. In the .bat file enter the following line and PowerShell script parameters. For instance, in this case, if the MyReport.ps1 has the parameter -days which shows how many days are to be included, enter in the .bat file the following line
powershell.exe c:\AAReport0\MyReport.ps1 -days 3
Note: This approach allows with minimal administrative effort the replacement of the script with an updated version and adding or removing parameters.
5. Make sure that script execution is allowed. To do so run
If the reply is "Restricted" please run
Do not add "-Executionpolicy Bypass" to the command line in the bat file -- it will work but it will run any time the the scheduled script is executed thus adding yet another possible point of failure.
6. Open Task Scheduler. Click on "Task Scheduler Library"
7. In the Action pane (on the right of the Task Scheduler) choose "New Folder"
8. Call the new Folder AppAssure and click OK. Please make a note to add all future AppAssure related tasks to that folder.
9. Select the AppAssure folder, right-click and select "Create Task". Do NOT choose "Create Basic Task".
10. In the general tab, give a name to the new task (i.e. AAReport0)
11. Click "Change the User and Group", type SYSTEM in the "Enter Object Name to Select", click Check Names to confirm it is identified correctly and click OK.
Note using the System account avoids disruptions caused by password changes or changes in the permissions for the user who runs the task.
12. Check the Run With Highest privileges checkbox
13. Select the "Triggers" Tab and click the new button.
14. In the Settings section choose the frequency and the time the new task is to be run.
15. In the Advanced Settings section, check the "Stop if Task runns longer than" checkbox and choose 12 hours from the drop down menu.
16. IMPORTANT: Check the Enabled Checkbox -- the task won't run until this checkbox is checked. Click OK to close the Trigger.
17. Select the Actions tab and click New.
18. In the Settings section, use the Browse Button to navigate to the .bat file (in this case AAReport0.bat), select it and click Open. Click OK to exit the New Action dialog
19. Select the Settings tab. Check the "Run task as soon as possible after a scheduled start is missed".
20. Make sure that the "Stop if Task runns longer than" checkbox is checked and set the duration to 12 hours.
21. Click OK to exit new task creation.
You are all set.
Test the new task by right-clicking the task name and choosing "Run"