﻿<?xml version="1.0" encoding="UTF-8"?>
<!--RSS generated by Windows SharePoint Services V3 RSS Generator on 5/19/2012 6:41:39 AM-->
<?xml-stylesheet type="text/xsl" href="/_layouts/RssXslt.aspx?List=815f255a-d0ef-4258-be2a-28487dc9975c" version="1.0"?>
<rss version="2.0">
  <channel>
    <title> : The SharePoint Blog Posts</title>
    <link>http://www.thesharepointblog.net/Lists/Posts/AllPosts.aspx</link>
    <description>RSS feed for the The SharePoint Blog Posts list.</description>
    <lastBuildDate>Sat, 19 May 2012 10:41:39 GMT</lastBuildDate>
    <generator>Windows SharePoint Services V3 RSS Generator</generator>
    <ttl>60</ttl>
    <image>
      <title> : The SharePoint Blog Posts</title>
      <url>/_layouts/images/homepage.gif</url>
      <link>http://www.thesharepointblog.net/Lists/Posts/AllPosts.aspx</link>
    </image>
    <item>
      <title>Deploying SharePoint Solutions with Task Scheduler</title>
      <link>http://www.thesharepointblog.net/Lists/Posts/ViewPost.aspx?ID=116</link>
      <description><![CDATA[<div><b>Body:</b> <div class=ExternalClassEFCE4A150BDA413598EB29D5B9EF97D2><div><font face=Arial><font size=2>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=2 face=Arial><strong>By: Kathryn Bartlett</strong></font></p></font></font>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>Task Scheduler is a lifesaver when it comes to deploying code late at night.<span style="">  </span>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.<span style="">  </span>There are three steps that are involved to make this work correctly:</font></font></p>
<p style="text-indent:-0.25in;margin:0in 0in 0pt 0.5in" class=MsoListParagraphCxSpFirst><font face=Arial><font size=2><span style=""><span style="">1.<span style="line-height:normal;font-variant:normal;font-style:normal;font-weight:normal">       </span></span></span>Create a PowerShell script</font></font></p>
<p style="text-indent:-0.25in;margin:0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle><font face=Arial><font size=2><span style=""><span style="">2.<span style="line-height:normal;font-variant:normal;font-style:normal;font-weight:normal">       </span></span></span>Create a batch file to run this PowerShell script</font></font></p>
<p style="text-indent:-0.25in;margin:0in 0in 10pt 0.5in" class=MsoListParagraphCxSpLast><font face=Arial><font size=2><span style=""><span style="">3.<span style="line-height:normal;font-variant:normal;font-style:normal;font-weight:normal">       </span></span></span>Create a new task in Task Scheduler that runs this batch file.</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>Note: The deployment code in this blog is taking place in a single-server installation of SharePoint 2010.<span style="">  </span></font></font></p>
<h1 style="margin:24pt 0in 0pt"><font color="#365f91"><font face=Arial><font size=2>Create a PowerShell Script</font></font></font></h1>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>First, we need to create a PowerShell script that will contain all of our commands.<span style="">  </span>Open your favorite text editor, and save the file to your C:\ drive as psscript.ps1.<span style="">  </span>As our first line, we need to add the SharePoint PowerShell snap-in with the following:</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><img alt="SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler" src="/PublishingImages/SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler_1.png"></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>What comes next would depend on what actions we need to take with our wsp.<span style="">  </span>Here, I will provide the appropriate syntax for adding, deploying, upgrading, retracting, and deleting wsps:</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2><span style=""></span><img style="width:657px;height:191px" alt="SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler" src="/PublishingImages/SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler_2.png" width=632 height=172></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>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.<span style="">  </span>To put your script to sleep for a minute, on a new line write the following:</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2><span style=""></span><img alt="SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler" src="/PublishingImages/SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler_3.png"></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>If your deployment requires resetting a service, you can do so with the following syntax.</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2><span style=""></span><img alt="SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler" src="/PublishingImages/SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler_4.png"></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>For the purposes of this blog, our PowerShell script will upgrade the solution package, restart the SharePoint 2010 Timer service, and call an iisreset.<span style="">  </span>Below is the full C:\psscript.ps1 that will be used throughout the remainder of this blog:</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><img style="width:910px;height:101px" alt="SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler" src="/PublishingImages/SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler_5.png" width=903 height=54></p>
<h1 style="margin:24pt 0in 0pt"><font color="#365f91"><font face=Arial><font size=2>Create a Batch File</font></font></font></h1>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>Now we need to create a batch file that will run our PowerShell file, C:\psscript.ps1.<span style="">  </span>This will only contain the following line:</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2><span style="">Picture6</span></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>For this blog, I’ve saved this file as C:\Deployment.bat</font></font></p>
<h1 style="margin:24pt 0in 0pt"><font color="#365f91"><font face=Arial><font size=2>Create a New Task in Task Scheduler</font></font></font></h1>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>From your SharePoint Server, open Task Scheduler under Administrator Tools.<span style="">  </span>In the Action menu, select Create Task…</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2><span style=""></span><img alt="SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler" src="/PublishingImages/SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler_7.png"></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>A dialog box to create a task will appear with multiple tabs.<span style="">  </span></font></font></p>
<h2 style="margin:10pt 0in 0pt"><font color="#4f81bd"><font face=Arial><font size=2>General</font></font></font></h2>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>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.</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2><span style=""><img alt="SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler" src="/PublishingImages/SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler_8.png"></span></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>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”.<span style="">  </span>Now move on to the Triggers tab.</font></font></p>
<h2 style="margin:10pt 0in 0pt"><font color="#4f81bd"><font face=Arial><font size=2>Triggers</font></font></font></h2>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>Now we need to add a new Trigger to tell our scheduler when to execute our task.<span style="">  </span>Clicking New… on the bottom left will open another dialog box.</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2><span style=""></span><img alt="Deploying_SharePoint_Solutions_with_Task_Scheduler" src="/PublishingImages/SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler_9.png"></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>Here, we have the ability to set what time the task should run, and set when the task should expire.<span style="">  </span>After selecting appropriate times for your deployment, hit OK and continue to the Actions tab.</font></font></p>
<h2 style="margin:10pt 0in 0pt"><font color="#4f81bd"><font face=Arial><font size=2>Actions</font></font></font></h2>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>This tab is where we specify what the task needs to accomplish.<span style="">  </span>Click New… to open another dialog box.</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2><span style=""></span><img alt="Deploying_SharePoint_Solutions_with_Task_Scheduler" src="/PublishingImages/SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler_10.png"></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>In this action, we are starting a program (our batch file), which we are selecting from our local file system. </font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>Hit OK and continue to the Conditions tab.</font></font></p>
<h2 style="margin:10pt 0in 0pt"><font color="#4f81bd"><font face=Arial><font size=2>Conditions</font></font></font></h2>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>In this tab we specify any additional conditions that would determine whether to run the task.<span style="">  </span>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”.<span style="">  </span></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2><span style=""></span><img alt="Deploying_SharePoint_Solutions_with_Task_Scheduler" src="/PublishingImages/SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler_11.png"></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>Continue to the last tab, Settings.</font></font></p>
<h2 style="margin:10pt 0in 0pt"><font color="#4f81bd"><font face=Arial><font size=2>Settings</font></font></font></h2>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>In this pane, we can select any additional settings which will affect this task.<span style="">  </span>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: ”.<span style="">  </span>I check this box and select “Immediately”.<span style="">  </span>I do not need to run this task again after deployment, so why keep it and clutter my list of necessary tasks?</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2><span style=""></span><img alt="SharePoint_Solutions_with_Task_Scheduler" src="/PublishingImages/SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler_12.png"></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>Hit OK to save your task.<span style="">  </span>You will then have to log in as the account that is scheduled to run the task.<span style="">  </span>To verify your task was created, click on Task Scheduler Library in the left navigation pane.</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2><span style=""></span><img alt="SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler" src="/PublishingImages/SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler_13.png"></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>If the task doesn’t appear immediately, click on Refresh in the right pane:</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2><span style=""></span><img alt="SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler" src="/PublishingImages/SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler_14.png"></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Arial><font size=2>You should now see your task listed.<span style="">  </span>If you click on your task, at the bottom in the middle, you can review your task settings.</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=2 face=Arial><img alt="" src="/PublishingImages/SharePoint_Blog_Deploying_SharePoint_Solutions_with_Task_Scheduler_15.png"></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=2 face=Arial><strong>By: Kathryn Bartlett</strong></font></p></div></div></div>
<div><b>Published:</b> 5/11/2012 1:25 PM</div>
]]></description>
      <author>WDC812\richardm</author>
      <pubDate>Fri, 11 May 2012 17:42:23 GMT</pubDate>
      <guid isPermaLink="true">http://www.thesharepointblog.net/Lists/Posts/ViewPost.aspx?ID=116</guid>
    </item>
  </channel>
</rss>
