﻿<?xml version="1.0" encoding="UTF-8"?>
<!--RSS generated by Windows SharePoint Services V3 RSS Generator on 11/24/2009 9:20:20 PM-->
<?xml-stylesheet type="text/xsl" href="/blogs/zach/_layouts/RssXslt.aspx?List=90bbfd11-c9a5-45cf-a77e-19559aae81ae" version="1.0"?>
<rss version="2.0">
  <channel>
    <title>Zach Rosenfield's SharePoint Blog: Posts</title>
    <link>http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/AllPosts.aspx</link>
    <description>RSS feed for the Posts list.</description>
    <lastBuildDate>Wed, 25 Nov 2009 05:20:20 GMT</lastBuildDate>
    <generator>Windows SharePoint Services V3 RSS Generator</generator>
    <ttl>60</ttl>
    <image>
      <title>Zach Rosenfield's SharePoint Blog: Posts</title>
      <url>/blogs/zach/_layouts/images/homepage.gif</url>
      <link>http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/AllPosts.aspx</link>
    </image>
    <item>
      <title>SharePoint 2010 Beta: ThreadOptions error</title>
      <link>http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/ViewPost.aspx?ID=51</link>
      <description><![CDATA[<div><b>Body:</b> <div class=ExternalClass58573E1B00724ACD820BAFBEB79D560F><div>Before everyone starts sending in messages about the &quot;ThreadOptions&quot; error you may be seeing when you open up the SharePoint Management Shell, let me explain:  this is a known issue.</div>
<div><br><strong>Why are you seeing it?  </strong>Well, because the Beta of SharePoint 2010 includes the PowerShell CTP3 of their 2.0 product; which does not have support for the ThreadOptions functionality we use to fix the <a href="/blogs/zach/Lists/Posts/Post.aspx?ID=34">&quot;threading issue&quot; discussed many months ago in my blog</a>.  Since this is not available, then the threading issue still applies--but when using the RTM build of PowerShell, this problem is no longer applicable!</div>
<div> </div>
<div>The RTM SharePoint 2010 product will install the RTM Build of PowerShell 2.0--which is actually available now (so if you can't wait, feel free to install 2.0 instead to avoid both this issue and the <a href="/blogs/zach/Lists/Posts/Post.aspx?ID=49">pre-req installer block</a>).</div>
<div> </div>
<div>The issue:</div>
<div><img alt="" src="/blogs/zach/Lists/Photos/Beta%20installer%20Issue.png"></div></div></div>
<div><b>Category:</b> PowerShell;SharePoint 2010</div>
<div><b>Published:</b> 11/19/2009 1:48 PM</div>
]]></description>
      <author>Zach Rosenfield</author>
      <category>PowerShell;SharePoint 2010</category>
      <pubDate>Thu, 19 Nov 2009 21:56:51 GMT</pubDate>
      <guid isPermaLink="true">http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/ViewPost.aspx?ID=51</guid>
    </item>
    <item>
      <title>SP+PS 2010: PowerShell to Create a Service Application</title>
      <link>http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/ViewPost.aspx?ID=50</link>
      <description><![CDATA[<div><b>Body:</b> <div class=ExternalClass2FFF0A0D31B0457681D84B2A09E398FA>
<div>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>One of the principles that PowerShell offers is the ability to “discover” what commands you need to run to do your tasks.<span>  </span>This principle mostly holds up—with on caveat: you have to “Know” the concepts about the task upfront for the commands to make sense.<span>  </span>I’m going to both demonstrate what this discovery means at the same time as showing how to create a service application.<span>  </span>The idea behind the discovery concept is that you should be able to take the knowledge behind creating 1 specific type of service application and re-use it to create any other type of service application*.<span>  </span><span> </span>Note that Search can be a bit more difficult because of all the flexibility built into 2010—the more flexible the system gets the more detailed setup can be.</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>First, you need to understand the concept of what is required to create a Service Application (I’m only going to discuss <i>non</i>-federated, so running on the same farm that is using it).<span>  </span>In the most simplified form: the following items are required for every service application:</font></font></p>
<p style="text-indent:-0.25in;margin:0in 0in 0pt 0.5in" class=MsoListParagraphCxSpFirst><span><span><font size=3 face=Calibri>1.</font><span style="font:7pt 'Times New Roman'">       </span></span></span><font size=3><font face=Calibri>The <strong>SPServiceApplication</strong>: this is the actual definition in the configuration database that will contain information like related databases and settings.<span>  </span>Note that this requires providing a web service Application Pool (More on this later).</font></font></p>
<p style="text-indent:-0.25in;margin:0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle><span><span><font size=3 face=Calibri>2.</font><span style="font:7pt 'Times New Roman'">       </span></span></span><font size=3><font face=Calibri>The <strong>SPServiceApplicationProxy</strong>: This is the “service connection” that is used for Web Applications to “talk” to the Service Application</font></font></p>
<p style="text-indent:-0.25in;margin:0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle><span><span><font size=3 face=Calibri>3.</font><span style="font:7pt 'Times New Roman'">       </span></span></span><font size=3><font face=Calibri>Start at least one <strong>SPServiceInstance</strong>: This is the actual “process” that will be used to run the Service Application code.<span>  </span>This can run on multiple servers to share load and provide high-availability—but only 1 is “required”.</font></font></p>
<p style="text-indent:-0.25in;margin:0in 0in 10pt 0.5in" class=MsoListParagraphCxSpLast><span><span><font size=3 face=Calibri>4.</font><span style="font:7pt 'Times New Roman'">       </span></span></span><font size=3><font face=Calibri>Attach the service to a <strong>SPServiceApplicationProxyGroup</strong>: This is the ‘group’ of service applications that a web application can be set to use.<span>  </span>There is a “Default” group that you can add services to that all web apps will be associated with by default.</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>Each service obviously has it’s own requirements (for example, you need to create databases for the User Profile service), but PowerShell will actually Prompt you for the “required” parameters and will give defaults for as many as it can.<span>  </span>Feel free to provide alternates to the defaults.</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>So, with that, let’s use the four requirements above to create a service app!<span>  </span>Metadata Service is a good starting point…</font></font></p>
<p style="text-indent:-0.25in;margin:0in 0in 10pt 0.5in" class=MsoListParagraph><span><span><font size=3 face=Calibri>1.</font><span style="font:7pt 'Times New Roman'">       </span></span></span><font size=3><font face=Calibri>Start one or more service instances.<span>  </span>Note that these exist regardless of whether they have any service applications to actually run.<span>  </span>We also want to wait for this to fully provision before continuing.</font></font></p>
<p style="text-indent:0.5in;margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:purple;font-size:10pt">$MetadataServiceInstance</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> (Get-SPServiceInstance |Where{</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$_</span><span style="font-family:'Courier New';color:black;font-size:10pt">.TypeName </span><span style="font-family:'Courier New';color:red;font-size:10pt">-eq</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Managed Metadata Web Service&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt">})<span>  </span><span> </span></span><span style="font-family:'Courier New';color:green;font-size:10pt">#Get a pointer to the Service Instance</span><span style="font-family:'Courier New';color:black;font-size:10pt"></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>  </span><span>    </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">if</span><span style="font-family:'Courier New';color:black;font-size:10pt">(</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$MetadataserviceInstance</span><span style="font-family:'Courier New';color:black;font-size:10pt">.Status </span><span style="font-family:'Courier New';color:red;font-size:10pt">-eq</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Disabled&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt">){<span>  </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt">$MetadataserviceInstance</span><span style="font-family:'Courier New';color:black;font-size:10pt"> | Start-SPServiceInstance<span>  </span>}<span>  </span></span><span style="font-family:'Courier New';color:green;font-size:10pt">#Start the Service Instance</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>  </span><span>    </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">while</span><span style="font-family:'Courier New';color:black;font-size:10pt">(</span><span style="font-family:'Courier New';color:red;font-size:10pt">-not</span><span style="font-family:'Courier New';color:black;font-size:10pt"> (</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$MetadataServiceInstance</span><span style="font-family:'Courier New';color:black;font-size:10pt">.Status </span><span style="font-family:'Courier New';color:red;font-size:10pt">-eq</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Online&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt">)){ <span>                        </span><span>                        </span></span><span style="font-family:'Courier New';color:green;font-size:10pt">#wait for provisioning to finish</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>      </span><span>      </span></span><b><span style="font-family:'Courier New';color:cadetblue;font-size:10pt">write-host</span></b><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><i><span style="font-family:'Courier New';color:cadetblue;font-size:10pt">-ForegroundColor</span></i><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">Yellow</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Waiting for Metadata service to provision&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt">; </span><b><span style="font-family:'Courier New';color:cadetblue;font-size:10pt">sleep</span></b><span style="font-family:'Courier New';color:black;font-size:10pt"> 5;</span></p>
<p style="text-indent:0.5in;margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt">}</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span> </span><span>     </span></span></p>
<p style="margin:0in 0in 0pt 0.5in" class=MsoListParagraphCxSpFirst><span style="font-family:'Courier New';color:black;font-size:10pt">Add-SPServiceApplicationProxyGroupMember -Identity </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$ProxyGroup</span><span style="font-family:'Courier New';color:black;font-size:10pt"> -Member </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$MetaDataServiceAppProxy</span><br><br></p>
<p style="text-indent:-0.25in;margin:0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle><span><span><font size=3 face=Calibri>2.</font><span style="font:7pt 'Times New Roman'">       </span></span></span><font size=3 face=Calibri>Get or Create an Application Pool.<span>  </span>If you already have one running other services you can get an existing one using the GET command, or create a new one like this.<br><br></font><span style="font-family:'Courier New';color:purple;font-size:10pt">$ManagedAccount</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> Get-SPManagedAccount | </span><b><span style="font-family:'Courier New';color:cadetblue;font-size:10pt">select</span></b><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><i><span style="font-family:'Courier New';color:cadetblue;font-size:10pt">-First</span></i><span style="font-family:'Courier New';color:black;font-size:10pt"> 1<span>  </span></span><span style="font-family:'Courier New';color:green;font-size:10pt">#Get a managed account. I RECOMMEND YOU CHANGE THIS LINE TO GET THE RIGHT ACCOUNT FOR YOU!</span><br><span style="font-family:'Courier New';color:purple;font-size:10pt">$ApplicationPool</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> New-SPIisWebServiceApplicationPool </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;SharePoint Hosted Services&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt"> -account $</span><span style="font-family:'Courier New';color:purple;font-size:10pt">ManagedAccount</span></p>
<p style="margin:0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle><font size=3 face=Calibri></font> </p>
<p style="margin:0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle><font size=3><font face=Calibri>*Note: this is NOT a Web Application “app pool”.<span>  </span>Do NOT create one of these for a web application –it will NOT work.<br><br></font></font></p>
<p style="text-indent:-0.25in;margin:0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle><span><span><font size=3 face=Calibri>3.</font><span style="font:7pt 'Times New Roman'">       </span></span></span><font size=3><font face=Calibri>Create the Service Application<br><br></font></font></p>
<p style="margin:0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle><span style="font-family:'Courier New';color:purple;font-size:10pt">$MetaDataServiceApp</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> New-SPMetadataServiceApplication -Name </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Metadata Service Application&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt"> -ApplicationPool </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$ApplicationPool</span><span style="font-family:'Courier New';color:black;font-size:10pt"></span></p>
<p style="margin:0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle><font size=3 face=Calibri></font> </p>
<p style="text-indent:-0.25in;margin:0in 0in 10pt 0.5in" class=MsoListParagraphCxSpLast><span><span><font size=3 face=Calibri>4.</font><span style="font:7pt 'Times New Roman'">       </span></span></span><font size=3><font face=Calibri>Create the proxy.<span>  </span>I also “attach it to the default proxy group using the -<font size=2><b>DefaultProxyGroup</b> </font>flag.</font></font></p>
<p style="margin:0in 0in 0pt 0.25in" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>   </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt">$MetaDataServiceAppProxy</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> New-SPMetadataServiceApplicationProxy -Name </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Metadata Service Application Proxy&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt"> -ServiceApplication </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$MetaDataServiceApp </span><span style="font-family:'Courier New';color:black;font-size:10pt">–DefaultProxyGroup</span></p>
<p style="margin:0in 0in 0pt 0.25in" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"></span> </p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>That’s it!<span>  </span>It’s a little basic, and can’t be part of a larger script that is going to be “re-run” very easily, so here’s a full script with some error handling to wrap the action…</font></font></p>
<div class=CODE>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:blue;font-size:10pt">try</span><span style="font-family:'Courier New';color:black;font-size:10pt">{</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>      </span></span><span style="font-family:'Courier New';color:green;font-size:10pt">#Managed Account</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>      </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt">$ManagedAccount</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> Get-SPManagedAccount | </span><b><span style="font-family:'Courier New';color:cadetblue;font-size:10pt">select</span></b><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><i><span style="font-family:'Courier New';color:cadetblue;font-size:10pt">-First</span></i><span style="font-family:'Courier New';color:black;font-size:10pt"> 1</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>      </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">if</span><span style="font-family:'Courier New';color:black;font-size:10pt"> (</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$ManagedAccount</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">-eq</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$NULL</span><span style="font-family:'Courier New';color:black;font-size:10pt">) { </span><span style="font-family:'Courier New';color:blue;font-size:10pt">throw</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;No Managed Accounts&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt"> }</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>      </span></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>      </span></span><span style="font-family:'Courier New';color:green;font-size:10pt">#App Pool</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>      </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt">$ApplicationPool</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> Get-SPIisWebServiceApplicationPool </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;SharePoint Hosted Services&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt"> -ea SilentlyContinue</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>      </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">if</span><span style="font-family:'Courier New';color:black;font-size:10pt">(</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$ApplicationPool</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">-eq</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$null</span><span style="font-family:'Courier New';color:black;font-size:10pt">){ </span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt">$ApplicationPool</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> New-SPIisWebServiceApplicationP<a name="_GoBack"></a>ool </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;SharePoint Hosted Services&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt"> -account </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$ManagedAccount</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">if</span><span style="font-family:'Courier New';color:black;font-size:10pt"> (</span><span style="font-family:'Courier New';color:red;font-size:10pt">-not</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$?</span><span style="font-family:'Courier New';color:black;font-size:10pt">) { </span><span style="font-family:'Courier New';color:blue;font-size:10pt">throw</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Failed to create an application pool&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt"> }</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>      </span>}</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>      </span></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>      </span></span><span style="font-family:'Courier New';color:green;font-size:10pt">#Create a Taxonomy Service Application</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>      </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">if</span><span style="font-family:'Courier New';color:black;font-size:10pt">((Get-SPServiceApplication |?{</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$_</span><span style="font-family:'Courier New';color:black;font-size:10pt">.TypeName </span><span style="font-family:'Courier New';color:red;font-size:10pt">-eq</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Managed Metadata Service&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt">})</span><span style="font-family:'Courier New';color:red;font-size:10pt">-eq</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$null</span><span style="font-family:'Courier New';color:black;font-size:10pt">){<span>      </span></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span><b><span style="font-family:'Courier New';color:cadetblue;font-size:10pt">Write-Progress</span></b><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Creating Taxonomy Service Application&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><i><span style="font-family:'Courier New';color:cadetblue;font-size:10pt">-Status</span></i><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Please Wait...&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt"></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span><span style="font-family:'Courier New';color:green;font-size:10pt">#get the service instance</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt">$MetadataServiceInstance</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> (Get-SPServiceInstance |?{</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$_</span><span style="font-family:'Courier New';color:black;font-size:10pt">.TypeName </span><span style="font-family:'Courier New';color:red;font-size:10pt">-eq</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Managed Metadata Web Service&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt">})</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">if</span><span style="font-family:'Courier New';color:black;font-size:10pt"> (</span><span style="font-family:'Courier New';color:red;font-size:10pt">-not</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$?</span><span style="font-family:'Courier New';color:black;font-size:10pt">) { </span><span style="font-family:'Courier New';color:blue;font-size:10pt">throw</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Failed to find Metadata service instance&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt"> }</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span><span> </span></span><span style="font-family:'Courier New';color:green;font-size:10pt">#Start Service instance</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">if</span><span style="font-family:'Courier New';color:black;font-size:10pt">(</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$MetadataserviceInstance</span><span style="font-family:'Courier New';color:black;font-size:10pt">.Status </span><span style="font-family:'Courier New';color:red;font-size:10pt">-eq</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Disabled&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt">){<span>  </span></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>                  </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt">$MetadataserviceInstance</span><span style="font-family:'Courier New';color:black;font-size:10pt"> | Start-SPServiceInstance<span>  </span></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>                  </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">if</span><span style="font-family:'Courier New';color:black;font-size:10pt"> (</span><span style="font-family:'Courier New';color:red;font-size:10pt">-not</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$?</span><span style="font-family:'Courier New';color:black;font-size:10pt">) { </span><span style="font-family:'Courier New';color:blue;font-size:10pt">throw</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Failed to start Metadata service instance&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt"> }</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span>} </span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span><span style="font-family:'Courier New';color:green;font-size:10pt">#Wait</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">while</span><span style="font-family:'Courier New';color:black;font-size:10pt">(</span><span style="font-family:'Courier New';color:red;font-size:10pt">-not</span><span style="font-family:'Courier New';color:black;font-size:10pt"> (</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$MetadataServiceInstance</span><span style="font-family:'Courier New';color:black;font-size:10pt">.Status </span><span style="font-family:'Courier New';color:red;font-size:10pt">-eq</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Online&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt">)){ </span><span style="font-family:'Courier New';color:green;font-size:10pt">#wait for provisioning</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>                  </span></span><b><span style="font-family:'Courier New';color:cadetblue;font-size:10pt">write-host</span></b><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><i><span style="font-family:'Courier New';color:cadetblue;font-size:10pt">-ForegroundColor</span></i><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">Yellow</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Waiting for Metadata service to provision&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt">; </span><b><span style="font-family:'Courier New';color:cadetblue;font-size:10pt">sleep</span></b><span style="font-family:'Courier New';color:black;font-size:10pt"> 5;</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span>}</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span><span style="font-family:'Courier New';color:green;font-size:10pt">#Create Service App</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt">$MetaDataServiceApp</span><span style="font-family:'Courier New';color:black;font-size:10pt"><span>  </span></span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> New-SPMetadataServiceApplication -Name </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Metadata Service Application&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt"> -ApplicationPool </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$ApplicationPool</span><span style="font-family:'Courier New';color:black;font-size:10pt"></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">if</span><span style="font-family:'Courier New';color:black;font-size:10pt"> (</span><span style="font-family:'Courier New';color:red;font-size:10pt">-not</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$?</span><span style="font-family:'Courier New';color:black;font-size:10pt">) { </span><span style="font-family:'Courier New';color:blue;font-size:10pt">throw</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Failed to create Metadata Service Application&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt"> }</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span><span style="font-family:'Courier New';color:green;font-size:10pt">#create proxy</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt">$MetaDataServiceAppProxy</span><span style="font-family:'Courier New';color:black;font-size:10pt"><span>  </span></span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> New-SPMetadataServiceApplicationProxy -Name </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Metadata Service Application Proxy&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt"> -ServiceApplication </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$MetaDataServiceApp</span><span style="font-family:'Courier New';color:black;font-size:10pt"> -DefaultProxyGroup</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">if</span><span style="font-family:'Courier New';color:black;font-size:10pt"> (</span><span style="font-family:'Courier New';color:red;font-size:10pt">-not</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$?</span><span style="font-family:'Courier New';color:black;font-size:10pt">) { </span><span style="font-family:'Courier New';color:blue;font-size:10pt">throw</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Failed to create Metadata Service Application Proxy&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt"> }</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>      </span>}</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt">}</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:blue;font-size:10pt">catch</span><span style="font-family:'Courier New';color:black;font-size:10pt"></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>    </span>{</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span><b><span style="font-family:'Courier New';color:cadetblue;font-size:10pt">Write-Output</span></b><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$_</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>      </span>}</span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3 face=Calibri></font> </p></div></div></div></div>
<div><b>Category:</b> PowerShell;SharePoint Administration;SharePoint 2010</div>
<div><b>Published:</b> 11/18/2009 1:18 PM</div>
]]></description>
      <author>Zach Rosenfield</author>
      <category>PowerShell;SharePoint Administration;SharePoint 2010</category>
      <pubDate>Wed, 18 Nov 2009 20:41:11 GMT</pubDate>
      <guid isPermaLink="true">http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/ViewPost.aspx?ID=50</guid>
    </item>
    <item>
      <title>SharePoint 2010 Beta Pre-Req Installer Error</title>
      <link>http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/ViewPost.aspx?ID=49</link>
      <description><![CDATA[<div><b>Body:</b> <div class=ExternalClass4208376F441A415F927F2A743C11DEC8><div>If you're seeing a failure with the SharePoint 2010 Beta Pre-Req Installer--it's most likely related to an existing PowerShell install.  In the Beta of 2010, the pre-req installer will attempt to install the PowerShell 2.0 CTP3.  The CTP does not support being installed &quot;over&quot; an existing PowerShell installation--which means that if you have PowerShell 1.0 installed you have two options:</div>
<div> </div>
<ul>
<li>Remove the Windows PowerShell feature prior to running the pre-req installer</li>
<li>Manually download and install the RTM version of PowerShell 2.0. The RTM version CAN be installed over an existing 1.0 install.</li></ul>
<p>I recommend the second option as SharePoint 2010 RTM will be using the RTM of PowerShell 2.0.</p>
<p>Hope this helps anyone who is seeing this issue!</p></div></div>
<div><b>Category:</b> PowerShell;SharePoint 2010</div>
<div><b>Published:</b> 11/18/2009 9:51 AM</div>
]]></description>
      <author>Zach Rosenfield</author>
      <category>PowerShell;SharePoint 2010</category>
      <pubDate>Wed, 18 Nov 2009 17:55:39 GMT</pubDate>
      <guid isPermaLink="true">http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/ViewPost.aspx?ID=49</guid>
    </item>
    <item>
      <title>SP+PS 2010: Understanding Features</title>
      <link>http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/ViewPost.aspx?ID=48</link>
      <description><![CDATA[<div><b>Body:</b> <div class=ExternalClassB65EEF77CB4C437FAE9A4906FA396C23><p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>SharePoint PowerShell was designed with Administrators in mind—so those of you who understand the difference between a “Feature” and a “FeatureDefiniton” might be a little concerned when you only see one feature related “noun”: “SPFeature”.<span style="">   </span>This is really because we could simplify this concept for PowerShell to only need one set of commands to manage functionality in your farms.<span style="">    </span>The important thing to realize is that no command will return an “SPFeature”, but rather an SPFeatureDefinition.<span style="">  </span>I’ll try to expect the rest of the concepts by example… <b style="">Here’s what you can expect from the following commands:</b></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>Starting with Get-SPFeature; this cmdlet will behave differently depending on the way it’s called.<span style="">  </span>Simply calling the command with no parameters will return all features installed in the farm.</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><span style="font-family:'Courier New';color:#c00000;font-size:10pt">PS&gt; Get-SPFeature</span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>If you wanted to see what features are installed at a specific scope, use “Client Side Filtering”:</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><span style="font-family:'Courier New';color:#c00000;font-size:10pt">PS&gt; Get-SPFeature |Where{ $_.Scope –eq “Web” }</span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>To get information about a specific feature, provide the Name or ID to the identity parameter of Get-SPFeature:</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><span style="font-family:'Courier New';color:#c00000;font-size:10pt">PS&gt; Get-SPFeature BaseWeb | select *</span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>If you wanted to get the list of features that are <i style="">Enabled </i>at a specific scope, you have to provide the Scope and object of interest.<span style="">  </span>The farm scoped features only require a flag—here’s the command to get all <i style="">Enabled </i>features at an SPFarm level:</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><span style="font-family:'Courier New';color:#c00000;font-size:10pt">PS&gt; Get-SPFeature -Farm</span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>To get the features enabled on a site collection use this:</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><span style="font-family:'Courier New';color:#c00000;font-size:10pt">PS&gt; Get-SPFeature –Site “http://sitename”</span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>Or on a specific SPWeb:</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><span style="font-family:'Courier New';color:#c00000;font-size:10pt">PS&gt; Get-SPFeature –Web “httP://sitename/blog”</span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font face=Calibri><font size=3>For those you who really wanted to know the details, the three previous commands are returning the SPFeatureDefinition for all the SPFeatures (which is really all <i style="">Enabled </i>features) at the provided scope.</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><u><font face=Calibri><font size=3>The other important commands are:</font></font></u></p>
<p style="text-indent:-0.25in;margin:0in 0in 0pt 0.5in" class=MsoListParagraphCxSpFirst><span style="font-family:Symbol"><span style=""><font size=3>·</font><span style="font:7pt 'Times New Roman'">         </span></span></span><font face=Calibri><font size=3>Install-SPFeature:<span style="">  </span>Use this command to install an SPFeatureDefinition into the farm. The files should already be deployed in the proper location (FEATURE directory) so you can just provide the “name” of the feature to be installed (Name is just the containing folder’s name)</font></font></p>
<p style="text-indent:-0.25in;margin:0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle><span style="font-family:Symbol"><span style=""><font size=3>·</font><span style="font:7pt 'Times New Roman'">         </span></span></span><font face=Calibri><font size=3>Uninstall-SPFeature: removes an installed SPFeatureDefinition from the farm.<span style="">  </span>Use just like Install</font></font></p>
<p style="text-indent:-0.25in;margin:0in 0in 0pt 0.5in" class=MsoListParagraphCxSpMiddle><span style="font-family:Symbol"><span style=""><font size=3>·</font><span style="font:7pt 'Times New Roman'">         </span></span></span><font face=Calibri><font size=3>Enable-SPFeature: turns on an SPFeature on the given Web, Site, Web Application, or the local Farm.<span style="">  </span>All that is required is the feature identity and the desired URL for the site, web or web app (for Farm level features you do not need to provide any URL)</font></font></p>
<p style="text-indent:-0.25in;margin:0in 0in 10pt 0.5in" class=MsoListParagraphCxSpLast><span style="font-family:Symbol"><span style=""><font size=3>·</font><span style="font:7pt 'Times New Roman'">         </span></span></span><font size=3><font face=Calibri>Disable-SPFeature: turns off an SPFeature at the given scope.<span style="">  </span>Use just like Enable.</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>As a final bonus—here’s a quick demo of how to use this knowledge to compare the features enabled on a given SPSite to the list of Site-Scoped features in the local SPFarm:</font></font></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:purple;font-size:10pt">$s1</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> Get-SPFeature -site </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;http://mysitetolookat&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt"><span style="">  </span></span><span style="font-family:'Courier New';color:green;font-size:10pt">#Get the list of features on our site</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:purple;font-size:10pt">$s2</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> Get-SPFeature |?{</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$_</span><span style="font-family:'Courier New';color:black;font-size:10pt">.Scope </span><span style="font-family:'Courier New';color:red;font-size:10pt">-eq</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">&quot;Site&quot;</span><span style="font-family:'Courier New';color:black;font-size:10pt">}<span style="">  </span>| </span><b><span style="font-family:'Courier New';color:cadetblue;font-size:10pt">sort</span></b><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:maroon;font-size:10pt">DisplayName</span><span style="font-family:'Courier New';color:black;font-size:10pt"><span style="">  </span></span><span style="font-family:'Courier New';color:green;font-size:10pt">#Get the list of available features (sorted)</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:purple;font-size:10pt">$results</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><b><span style="font-family:'Courier New';color:cadetblue;font-size:10pt">Compare-Object</span></b><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$s1</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$s2</span><span style="font-family:'Courier New';color:black;font-size:10pt"><span style="">  </span></span><span style="font-family:'Courier New';color:green;font-size:10pt">#Compare them</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"> </span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:blue;font-size:10pt">foreach</span><span style="font-family:'Courier New';color:black;font-size:10pt">(</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$row</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:blue;font-size:10pt">in</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$results</span><span style="font-family:'Courier New';color:black;font-size:10pt">){<span style="">   </span></span><span style="font-family:'Courier New';color:green;font-size:10pt">#Print the features in the master list not enabled on the site.</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span style="">  </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">switch</span><span style="font-family:'Courier New';color:black;font-size:10pt"> (</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$row</span><span style="font-family:'Courier New';color:black;font-size:10pt">.SideIndicator){ </span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span style="">    </span>=&gt;{ </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$row</span><span style="font-family:'Courier New';color:black;font-size:10pt">.InputObject }</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span style="">  </span>}</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt">}</span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3 face=Calibri>*Note that the above script only looks at “=&gt;”, but there could be Sandboxed Solutions that are unique to the site.<span style="">  </span>These would show with a “&lt;=” SideI</font><a name="_GoBack"></a><font size=3><font face=Calibri>ndicator instead.</font></font></p>
<div></div></div></div>
<div><b>Category:</b> SharePoint Administration;PowerShell</div>
<div><b>Published:</b> 11/16/2009 10:22 PM</div>
]]></description>
      <author>Zach Rosenfield</author>
      <category>SharePoint Administration;PowerShell</category>
      <pubDate>Tue, 17 Nov 2009 06:22:42 GMT</pubDate>
      <guid isPermaLink="true">http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/ViewPost.aspx?ID=48</guid>
    </item>
    <item>
      <title>SP+PS 2010: Custom Parameters</title>
      <link>http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/ViewPost.aspx?ID=47</link>
      <description><![CDATA[<div><b>Body:</b> <div class=ExternalClass820BCCFCFC424B5C8CF7AED792B51A03>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3 face=Calibri>Today’s post is one of my favorite new capabilities… custom parameters!<span>  </span>With SharePoint’s previous admin console (STSADM) you could create your own custom commands (Which you can still do with PowerShell in 2010—see </font><a href="http://stsadm.blogspot.com/2009/10/creating-custom-sharepoint-2010-cmdlets.html"><font size=3 face=Calibri>Gary’s post on Custom Cmdlets</font></a><font size=3><font face=Calibri> for a good starting point); but these required you to create your own command entirely in code from scratch, even if existing commands got you 90% of the way.<span>  </span>But in 2010, you can add only the parameters you need to existing commands by wrapping the existing cmdlet inside a function.<span>  </span>If you use this to make your own commands, please let me know!<span>  </span>I’m always interested to see what other parameters people are creating for themselves.<span>  </span>And with that, let’s begin!</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3 face=Calibri>Now those of you who read my blog know that my other main area of focus is Master Page design.<span>  </span>I’m a big fan of scripting all my repetitive steps—so when testing a new master page I want to deploy all possible templates that</font><a name="_GoBack"></a><font size=3><font face=Calibri> exist with my master page; but when you get ahold of your SharePoint 2010 beta you’ll not find a “MasterPage” setting on the SPWeb cmdlets…<span>  </span>Not to worry, we can add our own!</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>Here’s the initial syntax of Set-SPWeb (as of the 2010 Beta):</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><span></span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3 face=Calibri><img alt="" src="/blogs/zach/Blog%20Images%20and%20Files/PowerShell%20Intro%20Part%205/basic_post5_pic1.png"></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3 face=Calibri>First we need to take a copy of the <a href="/blogs/zach/Script%20Library/New-ScriptCmdlet.ps1">New-ScriptCmdlet.ps1</a> file from the <a href="/blogs/zach/Script%20Library/Forms/AllItems.aspx">script library</a>.<span>  </span>This is essentially a copy of James Brundage’s script from his </font><a href="http://blogs.msdn.com/powershell/archive/2008/05/09/fun-with-script-cmdlets.aspx"><font size=3 face=Calibri>Fun with Script Cmdlets</font></a><font size=3><font face=Calibri> blog post.<span>  </span>Essentially this script will “auto generate” a wrapper function based on the cmdlet passed into it. <span>  </span>For this situation I saved the <a href="/blogs/zach/Script%20Library/New-ScriptCmdlet.ps1">New-ScrpitCmdlet.ps1 </a>file to my C: drive and dot source the “New-ScriptCmdlet” function into my session so that I can call this command to generate the Set-SPWeb wrapper function: </font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3 face=Calibri>PS&gt; </font><span style="font-family:'Courier New';color:green;font-size:10pt">Get-Command Set-SPWeb | New-ScriptCmdlet Set-SPWeb | Set-Content Set-SPWeb.ps1</span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><span></span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri><img alt="" src="/blogs/zach/Blog%20Images%20and%20Files/PowerShell%20Intro%20Part%205/basic_post5_pic2.png"></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>Now that we generated the Set-SPWeb.ps1 function that we can add our logic to!<span>  </span>Open up this file and you’ll see a function that has the same syntax as the cmdlet…</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><span></span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri><img alt="" src="/blogs/zach/Blog%20Images%20and%20Files/PowerShell%20Intro%20Part%205/basic_post5_pic2b.png"></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>What we’re going to do today is add a “MasterPageRelativeUrl” to the cmdlet which takes a string to represent the relative path to the master page to apply.<span>  </span>First, we add the parameter to the “Param” list (I’ll highlight any “new” scripting I introduce):</font></font></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:blue;font-size:10pt">param</span><span style="font-family:'Courier New';color:black;font-size:10pt">(</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>    </span>[Parameter(Mandatory</span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$true</span><span style="font-family:'Courier New';color:black;font-size:10pt">, Position</span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt">0, ValueFromPipeline</span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$true</span><span style="font-family:'Courier New';color:black;font-size:10pt">)][Microsoft.SharePoint.PowerShell.SPWebPipeBind] </span><span style="font-family:'Courier New';color:purple;font-size:10pt">${Identity}</span><span style="font-family:'Courier New';color:black;font-size:10pt">,</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>    </span>[</span><span style="font-family:'Courier New';color:teal;font-size:10pt">System.String</span><span style="font-family:'Courier New';color:black;font-size:10pt">]</span><span style="font-family:'Courier New';color:purple;font-size:10pt">${RelativeUrl}</span><span style="font-family:'Courier New';color:black;font-size:10pt">,</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>    </span>[</span><span style="font-family:'Courier New';color:teal;font-size:10pt">System.String</span><span style="font-family:'Courier New';color:black;font-size:10pt">]</span><span style="font-family:'Courier New';color:purple;font-size:10pt">${Description}</span><span style="font-family:'Courier New';color:black;font-size:10pt">,</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>    </span>[Microsoft.SharePoint.PowerShell.SPWebTemplatePipeBind]</span><span style="font-family:'Courier New';color:purple;font-size:10pt">${Template}</span><span style="font-family:'Courier New';color:black;font-size:10pt">,</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>    </span>[</span><span style="font-family:'Courier New';color:teal;font-size:10pt">System.String</span><span style="font-family:'Courier New';color:black;font-size:10pt">]</span><span style="font-family:'Courier New';color:purple;font-size:10pt">${Theme}</span><span style="font-family:'Courier New';color:black;font-size:10pt">,</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>    </span>[Parameter(ValueFromPipeline</span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$true</span><span style="font-family:'Courier New';color:black;font-size:10pt">)][Microsoft.SharePoint.PowerShell.SPAssignmentCollection]</span><span style="font-family:'Courier New';color:purple;font-size:10pt">${AssignmentCollection}</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">,</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt"><span>    </span>[</span><span style="font-family:'Courier New';background:yellow;color:teal;font-size:10pt">System.String</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">] </span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">$MasterPageRelativeURL</span><span style="font-family:'Courier New';color:black;font-size:10pt"></span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt">)</span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>Then we need to handle this parameter being passed into the script.<span>  </span>Add the highlighted code to the Try block of the BEGIN section to collect the value and remove this from the parameters passed to the actual cmdlet.<span>  </span>Also, we need the Identity stored locally to use later so we’ll store that too:</font></font></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:blue;font-size:10pt">begin</span><span style="font-family:'Courier New';color:black;font-size:10pt"></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt">{</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>    </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">try</span><span style="font-family:'Courier New';color:black;font-size:10pt"> {</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>        </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt">$outBuffer</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$null</span></p>
<p style="text-indent:0.5in;margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:purple;font-size:10pt"><span>  </span><span style="background:yellow">$m_Identity</span></span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt"> </span><span style="font-family:'Courier New';background:yellow;color:red;font-size:10pt">=</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt"> </span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">$null</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">; </span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">$m_MasterPage</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt"> </span><span style="font-family:'Courier New';background:yellow;color:red;font-size:10pt">=</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt"> </span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">$null</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">;</span><span style="font-family:'Courier New';color:black;font-size:10pt"></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>        </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">if</span><span style="font-family:'Courier New';color:black;font-size:10pt"> (</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$PSBoundParameters</span><span style="font-family:'Courier New';color:black;font-size:10pt">.</span><span style="font-family:'Courier New';color:saddlebrown;font-size:10pt">TryGetValue</span><span style="font-family:'Courier New';color:black;font-size:10pt">(</span><span style="font-family:'Courier New';color:maroon;font-size:10pt">'OutBuffer'</span><span style="font-family:'Courier New';color:black;font-size:10pt">, [</span><span style="font-family:'Courier New';color:teal;font-size:10pt">ref</span><span style="font-family:'Courier New';color:black;font-size:10pt">]</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$outBuffer</span><span style="font-family:'Courier New';color:black;font-size:10pt">))</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>        </span>{</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>            </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt">$PSBoundParameters</span><span style="font-family:'Courier New';color:black;font-size:10pt">[</span><span style="font-family:'Courier New';color:maroon;font-size:10pt">'OutBuffer'</span><span style="font-family:'Courier New';color:black;font-size:10pt">] </span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> 1</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>        </span>}</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>      </span><span>  </span></span><span style="font-family:'Courier New';background:yellow;color:blue;font-size:10pt">if</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt"> (</span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">$PSBoundParameters</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">.</span><span style="font-family:'Courier New';background:yellow;color:saddlebrown;font-size:10pt">TryGetValue</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">(</span><span style="font-family:'Courier New';background:yellow;color:maroon;font-size:10pt">'masterpagerelativeurl'</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">, [</span><span style="font-family:'Courier New';background:yellow;color:teal;font-size:10pt">ref</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">]</span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">$m_MasterPage</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">))</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt"><span>        </span>{</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt"><span>            </span>[</span><span style="font-family:'Courier New';background:yellow;color:teal;font-size:10pt">void</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">]</span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">$PSBoundParameters</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">.</span><span style="font-family:'Courier New';background:yellow;color:saddlebrown;font-size:10pt">Remove</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">(</span><span style="font-family:'Courier New';background:yellow;color:maroon;font-size:10pt">'masterpagerelativeurl'</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">)</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt"><span>            </span>[</span><span style="font-family:'Courier New';background:yellow;color:teal;font-size:10pt">void</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">]</span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">$PSBoundParameters</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">.</span><span style="font-family:'Courier New';background:yellow;color:saddlebrown;font-size:10pt">TryGetValue</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">(</span><span style="font-family:'Courier New';background:yellow;color:maroon;font-size:10pt">'identity'</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">, [</span><span style="font-family:'Courier New';background:yellow;color:teal;font-size:10pt">ref</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">]</span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">$m_Identity</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">)</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt"><span>        </span>}</span><span style="font-family:'Courier New';color:black;font-size:10pt"></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>        </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt">$wrappedCmd</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$ExecutionContext</span><span style="font-family:'Courier New';color:black;font-size:10pt">.</span><span style="font-family:'Courier New';color:saddlebrown;font-size:10pt">InvokeCommand</span><span style="font-family:'Courier New';color:black;font-size:10pt">.</span><span style="font-family:'Courier New';color:saddlebrown;font-size:10pt">GetCommand</span><span style="font-family:'Courier New';color:black;font-size:10pt">(</span><span style="font-family:'Courier New';color:maroon;font-size:10pt">'Set-SPWeb'</span><span style="font-family:'Courier New';color:black;font-size:10pt">, [</span><span style="font-family:'Courier New';color:teal;font-size:10pt">System.Management.Automation.CommandTypes</span><span style="font-family:'Courier New';color:black;font-size:10pt">]::</span><span style="font-family:'Courier New';color:saddlebrown;font-size:10pt">Cmdlet</span><span style="font-family:'Courier New';color:black;font-size:10pt">)</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>        </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt">$scriptCmd</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> {&amp; </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$wrappedCmd</span><span style="font-family:'Courier New';color:black;font-size:10pt"> @PSBoundParameters }</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>        </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt">$steppablePipeline</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:red;font-size:10pt">=</span><span style="font-family:'Courier New';color:black;font-size:10pt"> </span><span style="font-family:'Courier New';color:purple;font-size:10pt">$scriptCmd</span><span style="font-family:'Courier New';color:black;font-size:10pt">.GetSteppablePipeline(</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$myInvocation</span><span style="font-family:'Courier New';color:black;font-size:10pt">.CommandOrigin)</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>        </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt">$steppablePipeline</span><span style="font-family:'Courier New';color:black;font-size:10pt">.Begin(</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$PSCmdlet</span><span style="font-family:'Courier New';color:black;font-size:10pt">)</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>    </span>} </span><span style="font-family:'Courier New';color:blue;font-size:10pt">catch</span><span style="font-family:'Courier New';color:black;font-size:10pt"> {</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>        </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">throw</span><span style="font-family:'Courier New';color:black;font-size:10pt"></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>    </span>}</span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt">}</span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>And the last step—we use one line of OM to set the master page on a given SPWeb object.<span>  </span>However, I’m going to wrap the command in a ShouldProcess and some other logic to handle poorly formed Master Page URLs. Just realize that only the line starting in Get-SPWeb is actually required. </font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>The Process section should now look like this:</font></font></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:blue;font-size:10pt">process</span><span style="font-family:'Courier New';color:black;font-size:10pt"></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt">{</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>    </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">try</span><span style="font-family:'Courier New';color:black;font-size:10pt"> {</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>        </span></span><span style="font-family:'Courier New';color:purple;font-size:10pt">$steppablePipeline</span><span style="font-family:'Courier New';color:black;font-size:10pt">.Process(</span><span style="font-family:'Courier New';color:purple;font-size:10pt">$_</span><span style="font-family:'Courier New';color:black;font-size:10pt">)</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt"><span>        </span></span><span style="font-family:'Courier New';background:yellow;color:blue;font-size:10pt">if</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">(</span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">$pscmdlet</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">.ShouldProcess(</span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">$m_Identity</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">.webUrl, </span><span style="font-family:'Courier New';background:yellow;color:maroon;font-size:10pt">&quot;MasterURL=$m_</span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">MasterPage</span><span style="font-family:'Courier New';background:yellow;color:maroon;font-size:10pt">&quot;</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">)){</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt"><span>        </span></span><span style="font-family:'Courier New';background:yellow;color:blue;font-size:10pt">if</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">(</span><span style="font-family:'Courier New';background:yellow;color:red;font-size:10pt">!</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">(</span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">$masterpage</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">.StartsWith(</span><span style="font-family:'Courier New';background:yellow;color:maroon;font-size:10pt">&quot;/_catalogs/masterpage/&quot;</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">))){ </span><b><span style="font-family:'Courier New';background:yellow;color:cadetblue;font-size:10pt">Write-Warning</span></b><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt"> </span><span style="font-family:'Courier New';background:yellow;color:maroon;font-size:10pt">&quot;Master Page paths generally start with the page /_catalogs/masterpage/&quot;</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">; }</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt"><span>           </span>Get-SPWeb </span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">$m_Identity</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">.webURL |</span><b><span style="font-family:'Courier New';background:yellow;color:cadetblue;font-size:10pt">%</span></b><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">{ </span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">$_</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">.MasterUrl </span><span style="font-family:'Courier New';background:yellow;color:red;font-size:10pt">=</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt"> </span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">$</span><span style="font-family:'Courier New';background:yellow;color:maroon;font-size:10pt">m_</span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">MasterPage</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">; </span><span style="font-family:'Courier New';background:yellow;color:purple;font-size:10pt">$_</span><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt">.Update() }</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';background:yellow;color:black;font-size:10pt"><span>        </span>}</span><span style="font-family:'Courier New';color:black;font-size:10pt"></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>    </span>} </span><span style="font-family:'Courier New';color:blue;font-size:10pt">catch</span><span style="font-family:'Courier New';color:black;font-size:10pt"> {</span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>        </span></span><span style="font-family:'Courier New';color:blue;font-size:10pt">throw</span><span style="font-family:'Courier New';color:black;font-size:10pt"></span></p>
<p style="margin:0in 0in 0pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt"><span>    </span>}</span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><span style="font-family:'Courier New';color:black;font-size:10pt">}</span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>So now if we dot-source this new Set-SPWeb script we’ll see that the MasterPageRelativeURL is now shown!</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><span></span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri><img alt="" src="/blogs/zach/Blog%20Images%20and%20Files/PowerShell%20Intro%20Part%205/basic_post5_pic3.png"></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>So now I can run Set-SPWeb to change the Master Page! If I use WhatIf I’ll see two entries, once for the cmdlet and once for my custom script:</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><span></span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri><img alt="" src="/blogs/zach/Blog%20Images%20and%20Files/PowerShell%20Intro%20Part%205/basic_post5_pic4.png"></font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>Command to change a master page:</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><b><span style="font-family:'Courier New';color:black;font-size:10pt">PS C:\&gt; </span></b><span style="font-family:'Courier New';color:#c00000;font-size:10pt">Set-SPWeb <a href="http://mybrandingsite">http://mybrandingsite</a> -MasterPageRelativeUrl &quot;/_catalogs/masterpage/zcustom.master&quot;</span></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>I've posted the final <a href="/blogs/zach/Script%20Library/Set-SPWeb.ps1">Set-SPWeb.ps1</a> file in the <a href="/blogs/zach/Script%20Library/Forms/AllItems.aspx">Script Library</a> as well.</font></font></p>
<p style="margin:0in 0in 10pt" class=MsoNormal><font size=3><font face=Calibri>NOTE: you can still force PowerShell to use the CMDLET directly by calling “Microsoft.sharepoint.powershell\Set-SPWeb” or the Function directly using “\Set-SPWeb”.</font></font></p>
<div></div></div></div>
<div><b>Category:</b> SharePoint 2010;PowerShell</div>
<div><b>Published:</b> 11/14/2009 2:39 PM</div>
]]></description>
      <author>Zach Rosenfield</author>
      <category>SharePoint 2010;PowerShell</category>
      <pubDate>Sat, 14 Nov 2009 22:38:53 GMT</pubDate>
      <guid isPermaLink="true">http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/ViewPost.aspx?ID=47</guid>
    </item>
  </channel>
</rss>