SharePoint Events

  5/13/2013 - Conference: SharePoint Summit 2013
  5/21/2013 - Webcast: SharePoint 2013 and ECM: Content Migration and Storage
  5/22/2013 - Webcast: Managing CAD in SharePoint
  5/23/2013 - Webcast: SharePoint Document Automation and E-Forms for Financial Services
  5/24/2013 - Webcast: What's New in Search for SharePoint 2013

 SharePoint Videos

  Why SharePoint 2013
  SharePoint 2013 Launch
  SharePoint 2013 Migration and Governance
  SharePoint 2013 and Enterprise Content Management
  Top Benefits of SharePoint 2013
  What's New in Business Intelligence in Office and SharePoint 2013
  SharePoint and Office 2013 Integration
  SharePoint 2013 Infrastructure Preview
  SharePoint, Lync, and, Exchange in the Cloud with Office 365
  Advanced Reporting in SharePoint with Microsoft Power View

 Archives

Opening SharePoint Links in a new windowUse SHIFT+ENTER to open the menu (new window).
Mail Enabled Lists vs. The Missing Windows 2008 POP3/IMAP Server Use SHIFT+ENTER to open the menu (new window).
7 Tools for SharePoint DevelopersUse SHIFT+ENTER to open the menu (new window).
Public Facing Masterpage TechniquesUse SHIFT+ENTER to open the menu (new window).
How to Quickly Deploy and Activate a Timer Service to Your Site CollectionUse SHIFT+ENTER to open the menu (new window).
Custom SharePoint Master Page Feature with WSP BuilderUse SHIFT+ENTER to open the menu (new window).
Date Math with InfoPathUse SHIFT+ENTER to open the menu (new window).
Enterprise Search Tricks and Tips Part 1Use SHIFT+ENTER to open the menu (new window).
Populating Word Documents With SharePoint Data. Try The DIP!Use SHIFT+ENTER to open the menu (new window).
Programmatic Deep Dive into Blank SharePoint Lookup ColumnsUse SHIFT+ENTER to open the menu (new window).
1 - 10 Next
Deploying SharePoint Solutions with Task Scheduler

By: Kathryn Bartlett

Task Scheduler is a lifesaver when it comes to deploying code late at night.  Instead of having to be directly in front of your computer, dead tired, going through the simple steps up adding/deploying/upgrading wsp files, we can write a PowerShell script that will run at a specified time.  There are three steps that are involved to make this work correctly:

1.       Create a PowerShell script

2.       Create a batch file to run this PowerShell script

3.       Create a new task in Task Scheduler that runs this batch file.

Note: The deployment code in this blog is taking place in a single-server installation of SharePoint 2010. 

Create a PowerShell Script

First, we need to create a PowerShell script that will contain all of our commands.  Open your favorite text editor, and save the file to your C:\ drive as psscript.ps1.  As our first line, we need to add the SharePoint PowerShell snap-in with the following:

SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler

What comes next would depend on what actions we need to take with our wsp.  Here, I will provide the appropriate syntax for adding, deploying, upgrading, retracting, and deleting wsps:

SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler

Between each deployment command that causes recycling of app pools, I like to pause the script for a minute to ensure that everything is back in order before continuing with the next statement.  To put your script to sleep for a minute, on a new line write the following:

SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler

If your deployment requires resetting a service, you can do so with the following syntax.

SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler

For the purposes of this blog, our PowerShell script will upgrade the solution package, restart the SharePoint 2010 Timer service, and call an iisreset.  Below is the full C:\psscript.ps1 that will be used throughout the remainder of this blog:

SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler

Create a Batch File

Now we need to create a batch file that will run our PowerShell file, C:\psscript.ps1.  This will only contain the following line:

Picture6

For this blog, I’ve saved this file as C:\Deployment.bat

Create a New Task in Task Scheduler

From your SharePoint Server, open Task Scheduler under Administrator Tools.  In the Action menu, select Create Task…

SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler

A dialog box to create a task will appear with multiple tabs. 

General

Here, we need to specify a name, verify the account under which this task will run, and select what settings to run the task with.

SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler

My main reason for scheduling deployment via task scheduling is due to the fact I will not be able to be at my computer, so I always select “Run whether user is logged on or not”.  Now move on to the Triggers tab.

Triggers

Now we need to add a new Trigger to tell our scheduler when to execute our task.  Clicking New… on the bottom left will open another dialog box.

Deploying_SharePoint_Solutions_with_Task_Scheduler

Here, we have the ability to set what time the task should run, and set when the task should expire.  After selecting appropriate times for your deployment, hit OK and continue to the Actions tab.

Actions

This tab is where we specify what the task needs to accomplish.  Click New… to open another dialog box.

Deploying_SharePoint_Solutions_with_Task_Scheduler

In this action, we are starting a program (our batch file), which we are selecting from our local file system.

Hit OK and continue to the Conditions tab.

Conditions

In this tab we specify any additional conditions that would determine whether to run the task.  In this instance, I want to uncheck “Start the task only if the computer is on AC power” and check “Wake the computer to run this task”. 

Deploying_SharePoint_Solutions_with_Task_Scheduler

Continue to the last tab, Settings.

Settings

In this pane, we can select any additional settings which will affect this task.  In this section, I typically leave all at their default settings except for “If the task is not scheduled to run again, delete it after: ”.  I check this box and select “Immediately”.  I do not need to run this task again after deployment, so why keep it and clutter my list of necessary tasks?

SharePoint_Solutions_with_Task_Scheduler

Hit OK to save your task.  You will then have to log in as the account that is scheduled to run the task.  To verify your task was created, click on Task Scheduler Library in the left navigation pane.

SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler

If the task doesn’t appear immediately, click on Refresh in the right pane:

SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler

You should now see your task listed.  If you click on your task, at the bottom in the middle, you can review your task settings.

By: Kathryn Bartlett

        

Comments

There are no comments yet for this post.
Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Your Name *


e-mail address *


Website (optional)


Comment *


Attachments

 Subscribe

  GigWerks RSS  Gig Werks Mailing List 

 Contact Us

 Connect

 Resources

  On Demand SharePoint Webcast Recordings
  Upcoming Webinars
  SharePoint Resources
  Business Intelligence Resources
  Gig Werks Website



©2009 Gig Werks. All rights reserved. Privacy Policy