0

I have a powershell script to delete a list . I want to schedule it to run once a year . Is there a way to schedule a powershell script ?

  • Why don't you write a C# Console Application and use Task Scheduler to schedule it yearly ? – Arsalan Adam Khatri Aug 4 '14 at 18:51
  • i have powershell script ready , dont wnt to write code again . – Nikhil J Aug 11 '14 at 15:52
3

You can run this as a Windows Schedule task to run once a year.

  • load Task Scheduler from Start > All Programs > Accessories > System Tools
  • create a new scheduled task, click Create Task from the right-hand “Actions” panel. At a minimum, you should fill out the following information:

General Tab

  • Name of the task – e.g., Intranet Backup. A description is also useful, but not mandatory

  • Ensure the user account running the task has the following permissions:

  • Log on as a batch job rights in the User Rights Assignment section of the server Local Security Policy. These rights could be set on the
    server itself or by Group Policy if managed from Active Directory –
    see http://technet.microsoft.com/en-us/library/dd277404.aspx for
    details

  • Permissions to use PowerShell on the SharePoint farm. You can add these for a new user by running Add-SPShellAdmin –UserName domain\username in the SharePoint 2010 Management Shell console as a current administrator – see http://technet.microsoft.com/en-us/library/ff607596.aspx for details

  • Permissions to be able to perform the script operation in SharePoint. For example, for the site collection backup in this example, the account used in the scheduled task required:

  • dbo access in SQL to the database hosting the site collection

  • Membership of the local Administrators group on the server – you may be able to experiment with fewer permissions than this, but this was required on my development server, which is also a domain controller

  • Select Run whether the user is logged in or not and tick the Do not store password checkbox

  • For certain operations, you may also need to enable the Run with highest privileges option. As this should only be enabled when necessary, I would recommend testing the script from Task Scheduler with the option disabled and only enable if the script does not work without it

Triggers Tab

Click New and add your schedule, as required. In the example below I am going for daily at 2:00AM

Actions Tab

Click New. Ensure the action is set to Start a program and type Powershell.exe in the “Program/Script” box. In the “Add arguments (optional)” box, type &'c:\scripts\script.ps1' replacing the path and name with the details for your script. Wrapping the file path and name in single quotation marks allows you to specify spaces in the text.

When you click OK to confirm task creation, you will be prompted to enter the password for the account you selected to run the script. Enter the password and click OK.

You should now see your script in the Task Scheduler Library (if not, click Refresh in the right-hand panel). To test the script, highlight it in the console and click Run from the right-hand panel.

Check that the changes required are performed (for this example it was checking to ensure the backup file was being created in the folder when the task ran) and leave it to run on the schedule. Don’t forget to perform regular checks in the future to test the script continues to run as expected

http://get-spscripts.com/2011/01/running-sharepoint-powershell-script.html

  • Since i do not have arguments . I did set the "Program/Script" box directly to script : powershell -file "C:\NIKHIL\Powershell Scripts\ArchieveSitelistToNewList.ps1" . I can directly type in run and make the script work . So this also work . blogs.technet.com/b/heyscriptingguy/archive/2012/08/11/… – Nikhil J Aug 6 '14 at 19:55
3

Use Windows Task Scheduler. I sometimes use it for console applications. You can schedule the .ps1 file to run at yearly intervals.

http://windows.microsoft.com/en-ca/windows/schedule-task#1TC=windows-7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.