Thursday, 13 January 2011

Running a SharePoint PowerShell script from Task Scheduler

There are often times where you may want to run a PowerShell script for SharePoint on a schedule – for example, a backup routine, report, or script to automate a process – just like the good old days of running a batch file in Task Scheduler. Well, things aren’t really that different these days either – yes, the scripting language may have changed, but Task Scheduler can still be used as before.

In this example, I am going to script the backup of a site collection and run it every night at 2:00AM. First, the script:

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
Backup-SPSite -Identity
http://intranet.pacdomain2.local -Path C:\Install\Intranet.bak –Force

Although the script is quite simple, note the Add-PSSnapin command on the first line. We need this because we are going to run the script using the standard Windows PowerShell console application and not the SharePoint 2010 Management Shell that has the snap-in already loaded. The –erroraction switch is there to prevent any errors should the snap-in already be loaded through a profile on the server.

Save your script to a local drive on the server as a PS1 file.

Next, load Task Scheduler from Start > All Programs > Accessories > System Tools. The version I am using here ships with Windows Server 2008 R2, but the concepts should be the same on earlier releases.


To 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 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 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.


  1. Great post. I am having a problem, however. I have created my SharePoint script to check the status of the content being crawled, when it last completed the crawl, the schedule, etc. then email it to me in a .csv file.

    If I open windows powershell and run the script, it sends the message fine and the .csv has the necessary information. However, if I create the task in Task Scheduler and run it, it sends the attachment but it doesn't have the information in it. I threw a 'start-transcript' into the script and the error that comes up is that it can't find the SPFarm when it tries to execute the script.

    The script adds the proper snapin to get the SharePoint items, but it fails only when ran using task scheduler. Any ideas?

  2. Nevermind, I resolved my issue. What I did was create a batch file that ran powershell then called the command to run my script. Something like this:

    powershell -command "& ' C:\Utility\crawl.ps1 ' "

  3. Clear interface and effectiveness of this scheduler looks suitable for all user community. But its seamless scheme is not for serious and specific projects and tasks. In my projects we use comindware task management and its flexibility to solve specific tasks looks rather perspective. I think that Windows task managers are not the best tool for it.

  4. This comment has been removed by a blog administrator.

  5. @sam Thanks for the tip on the catch file. It fixed my issue too with running

  6. This comment has been removed by the author.

  7. How can I do it programatically using Powershell for create Task Scheduler ?thx

  8. Thank you so much!! Time saving...:)

  9. Thank you. Saved a lot of time. My script didn't work without Add-PSSnapin .

  10. Mở bán chung cư Eco Spring Nguyễn Xiển | Thông tin chung cư GoldSeason Nguyễn Tuân | Mở bán chung cư Gold Season | Phân phối chung cư GoldSeason 47 Nguyễn Tuân | Tin tức chung cư 47 nguyễn tuân | Thông tin dự án GoldSeason | Tìm hiểu chủ đầu tư GoldSeason | Thông tin chung cư Eco Spring

  11. chung cu gemek du an gemek premium mo bat dot moi nam 2016.
    Du an can ho cao cap Gemek Premium chinh thuc mo ban dot 1.
    Danh sach chung cu Ha Noi can ho chung cu cac quan Ha Dong, Cau Giay, Hoang Mai….
    FLC Group ra mat du an cao cap tai Ha Dong du an flc quang trung voi quan the tien ich chat luong cao.
    Mot du an cao cap voi quan the can ho chung cu va biet thu lien ke chung cu flc garden city quan nam Tu Liem, Ha Noi.
    Mot du an cao cap voi quan the can ho chung cu Tay Ho chung cu 69b thuy khue chu dau tu SUN GROUP.
    Chung cu mat duong Nguyen Xien Eco Green City mo ban block Eco Spring.
    Chung cu mat duong Quang Trung flc star tower mo ban FLC Star Tower. Thong tin chung cu Ha Noi du an bds chung cu ha noi.


  12. If you schedule your home changing with one of good packers and movers in Riyadh then it is for certain that you will have hassle-free relocation experience. You will have peace of mind. You will save your valuable money, energy and time. You will need to do nothing as all jobs associated with your move will be properly done and carried out by experts of professional movers and packers in Riyadh. Experts will pack your household belongings carefully and load them onto the truck for safe transport. They will use especially designed goods carriers or trucks to transport your possessions to your new destination door step. These people will also unpack containers and rearrange items at your new place. A good mover will also provide goods insurance policy along with service. Plus hence you will have good thing about insurance for your goods during transit. It indicates mover will cover the loss if your possessions are sadly damaged or lost in transit. So it is but apparent that selecting services of a good moving company in Riyadh will ease your entire moving issues whether you are shifting from one vicinity to another within metropolis of Hyderabad or transferring to a new city
    شركة تخزين الاثاث بالرياض
    افضل شركة تنظيف بالرياض
    افضل شركة تنظيف خزانات بالرياض
    افضل شركة مكافحة حشرات بالدمام

    A move is only considered as a successful move when it’s guarded and superintend. Yes management is a key factor for a safe relocation. If you are planning for a moving and shifting, then you are supposed to be managed. And this management needs to be clearly reflected in your packing and moving. In case you are unable to spare adequate time for your managed move, then we would suggest you to go for the best remedy of that which is Removal Company.

    شركة نقل اثاث بالرياض
    شركة رش مبيدات بالرياض
    افضل شركة مكافحة حشرات وفئران
    افضل شركة غسيل مجالس بالرياض

    شراء اثاث مستعمل بالرياض
    كشف تسربات المياه
    افضل شركة تنظيف منازل بالرياض

  13. - رش مبيدات
    تتميز شركة الاول بانها تستخدم افضل معدات رش المبيدات في المملكة
    وتم تعريف المبيد الحشري على انه هو مبيد آفات يستخدم ضد الحشرات في جميع أطوار نموها.

    وتستخدم الاول جميع انواع المبيدات مثل :
    1- المبيدات النقية
    2- المبيدات البودرة
    3- المبيدات المركزة المستحلب
    4- المبيدات القابلة للذوبان في مواد اخرى مذيبه
    بالاضافة الى وسائل الرش مثل الرش الدخانى والرزازى والتعفيري والضبابى البارد والحرارى
    الاول لتفوقها في مجال رش المبيدات تعد افضل شركة رش مبيدات شمال بالرياض وافضل شركة رش مبيدات بجدة وافضل شركة رش مبيدات بالمدينة المنورة وشركة رش مبيدات بالاحساء وشركة رش مبيدات بالخبر و شركة رش مبيدات بالخرجو شركة رش مبيدات بابها و شركة رش مبيدات بالقصيم و شركة رش مبيدات بينبع
    وافضل شركة رش مبيدات بالجبيل

  14. Hiện tại sàn giao dịch Kiều Anh đang mở bán dự án Grand World Phú Quốc

  15. Our Browns House Flag hangs vertically and provides a top sleeve for insertion of your flagpole. The Browns House Flag measures 28x42 inches, is constructed of 2-ply polyester, and both sides are dye sublimated with the NFL team logo as shown.
    house divided flags nhl
    nfl house flagswholesale Minnesota Vikings banners
    New York Giants american banners

  16. Impiegando design tradizionale del club, il kit a casa Pescara 16-17 presenta un aspetto a strisce in bianco e blu. Un modo interessante costruito V-collare e dettagli sui polsini e orlo completano il look unico della maglia Pescara 2016-17, che si combina con pantaloncini bianchi e calzettoni.maglie calcio 2017,
    maglie calcio poco prezzo, Maglia Athletic Bilbao 2017
    comprar Maglia Atletico Madrid

  17. Impiegando design tradizionale del club,

  18. This comment has been removed by the author.

  19. This comment has been removed by the author.

  20. This comment has been removed by the author.

  21. This comment has been removed by the author.

  22. Wow, Excellent post. This article is really very interesting and effective. I think its must be helpful for us. Thanks for sharing your informative.
    SEO jobs in Hyderabad
    SharePoint jobs in Hyderabad
    SharePoint jobs in Chennai

  23. Cheap NFL Jerseys Ray Ban Outlet Longchamp Outlet Toms Outlet Adidas Yeezy Ray Ban Sunglasses Yeezys Kade Sapde Adidas Outlet Nike Store Under Armour Timberland Jordan 12 Keds Shoes Nike Air Max Toms Outlet Ultra Boost Cheap MLB Jerseys Adidas NMD Oakley Outlet Kate Spade Outlet Adidas Outlet Nike Air Max 90 Timberland Outlet Adidas NMD Adidas EQT Ralph Lauren UK Jordan 4 Cheap Jordan Adidas NMD Kate Spade Outlet Longchamp Outlet Adidas NMD R1 Nike Air Max90 Running shoes Basketball Shoes Michael Kors bags Adidas Yeezy Asics shoes Coach online Timberland shoes Jordan Shoes Adidas Yeezy Shoes Nike Air Vapor Max ray ban sunglasses Nike Outlet longchamp bags Adidas Shoes Nike Shoes Yeezy Shoes james Sale Adidas NMD Jordan 12 Air Max Outlet Asics Gel Flip Flopst ray ban sunglasses oakley sunglasses oakley sunglasses cheap oakley sunglasses cheap rayban sunglasses Nike Shoes

  24. Nice blog with having good information. It’s very useful for everyone. Thanks and keep posting this type of blog
    CCNA jobs in Hyderabad .

  25. This comment has been removed by the author.


  27. This comment has been removed by the author.

  28. Thống kê 1 số dự án như sau:chung cư hồng hà eco city chungcuhonghaecocity và cả dự án giá rẻ chung cư giá gốc hà nội chung cư đường giải phóng căn hộ giá rẻ long biên hãy tham khảo nhé

  29. Sửa điện nước tại quận 1
    Sửa điện nước tại quận 2
    sửa điện nước tại quận 3
    sửa điện nước tại quận 4
    sửa điện nước tại quận 5
    Sửa điện nước tại quận 6
    Sửa điện nước tại quận 7
    Sửa điện nước tại quận 8
    Sửa điện nước tại quận 9
    Sửa điện nước tại quận 10
    Sửa điện nước tại quận 11
    Sửa điện nước tại quận 12
    Sửa điện nước tại quận Tân Bình
    Sửa điện nước tại quận Tân Phú
    Sửa điện nước tại quận Thủ Đức
    Sửa điện nước tại quận Bình Thạnh
    Sửa điện nước tại quận Gò Vấp
    sửa điện nước tại quận Phú Nhuận

  30. Sửa máy bơm nước tại quận 1
    Sửa máy bơm nước tại quận 2
    Sửa máy bơm nước tại quận 3
    Sửa máy bơm nước tại quận 4
    Sửa máy bơm nước tại quận 5
    Sửa máy bơm nước tại quận 6
    Sửa máy bơm nước tại quận 7
    Sửa máy bơm nước tại quận 8
    Sửa máy bơm nước tại quận 9
    Sửa máy bơm nước tại quận 10
    Sửa máy bơm nước tại quận 11
    Sửa máy bơm nước tại quận 12
    Sửa máy bơm nước tại quận Tân Bình
    Sửa máy bơm nước tại quận Tân Phú
    Sửa máy bơm nước tại quận Thủ Đức
    Sửa máy bơm nước tại quận Bình thạnh
    Sửa máy bơm nước tại quận gò Vấp
    Sửa máy bơm nước tại quận phú nhuận
    Sửa máy bơm nước tại quận bình Tân
    Sửa máy bơm nước tại quận nhà bè

  31. This comment has been removed by the author.

  32. This comment has been removed by the author.