<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>SharePoint Automation</title>
	
	<link>http://blog.falchionconsulting.com</link>
	<description>Gary Lapointe - Founding Partner, Aptillon, Inc.</description>
	<lastBuildDate>Tue, 15 May 2012 14:34:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/AutomatingSharePoint" /><feedburner:info uri="automatingsharepoint" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>International SharePoint Conference 2012 Follow-up</title>
		<link>http://feedproxy.google.com/~r/AutomatingSharePoint/~3/CfbyiV2dU80/</link>
		<comments>http://blog.falchionconsulting.com/index.php/2012/05/international-sharepoint-conference-2012-follow-up/#comments</comments>
		<pubDate>Tue, 15 May 2012 14:34:23 +0000</pubDate>
		<dc:creator>Gary Lapointe</dc:creator>
				<category><![CDATA[PowerShell Scripting]]></category>
		<category><![CDATA[Speaking]]></category>
		<category><![CDATA[ISCLondon]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SharePoint 2010]]></category>

		<guid isPermaLink="false">http://blog.falchionconsulting.com/index.php/2012/05/international-sharepoint-conference-2012-follow-up/</guid>
		<description><![CDATA[.codebox { overflow:auto; height:400px; border: solid 1px black; padding:5px;} First off I apologize for the delay in getting this post out – I’ve been fraught with injuries and illness since my return from London and just haven’t had the time or mental capacity to think about writing anything. During my sessions at the ISC I [...]]]></description>
			<content:encoded><![CDATA[<style>









.codebox { overflow:auto; height:400px; border: solid 1px black; padding:5px;}</style>  <p>First off I apologize for the delay in getting this post out – I’ve been fraught with injuries and illness since my return from London and just haven’t had the time or mental capacity to think about writing anything. </p>  <p>During my sessions at the <a href="http://www.internationalsharepointconference.com/Pages/default.aspx" target="_blank">ISC</a> I demonstrated (along with <a href="http://www.harbar.net/" target="_blank">Spence Harbar</a> and <a href="http://www.chandima.net" target="_blank">Chan Kulathilake</a>) how we could use PowerShell to provision the entire SharePoint 2010 Farm used throughout the IT track at the conference (yeah, no pressure – everyone presenting after me was depending on my scripts functioning). This Farm consisted of numerous servers beyond the SharePoint servers but my scripts were only responsible for getting SharePoint configured. For reference here’s a screenshot showing the server topology:</p>  <p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blog.falchionconsulting.com/wp-content/uploads/2012/05/image.png" width="792" height="451" /></p>  <p>Before we could run the scripts on any servers there was some prep work that we had to do ahead of time. Specifically we did the following on each of the SharePoint servers (SP01-06):</p>  <ul>   <li>Installed SharePoint 2010 and Office Web Applications with SP1 and the October 2011 CU      <ul>       <li>The installation of the bits could have been scripted but doing so during a live session at a conference just wasn’t practical due to time limitations. </li>     </ul>   </li>    <li>Disable: UAC, Firewall, IE ESC      <ul>       <li>This isn’t something you’d typically do for a production environment but doing so reduced potential complications and annoyances when it came to doing demos. I typically will disable all these things when doing my provisioning and then selectively re-enable them after I’ve confirmed that the Farm is running properly – this makes troubleshooting much easier. </li>     </ul>   </li>    <li>PowerShell Prep      <ul>       <li>I updated the all users all hosts profile on each server so that the SharePoint PowerShell snap-in would be loaded for any editor so that we wouldn’t be tied to the management shell. (We also installed the PowerShell ISE). </li>        <li>I enabled remoting on all servers so that I could build each server remotely, thereby foregoing the need to have to log into each server to kick off the script in parallel. I also created a custom configuration session which loaded the SharePoint PowerShell snap-in automatically and made sure the threading model was set appropriately. The following shows the commands I executed to enable remoting:          <div style="border-bottom: black 1px solid; border-left: black 1px solid; overflow: auto; border-top: black 1px solid; border-right: black 1px solid">           <pre><span style="color: #5f9ea0; font-weight: bold">Enable-PSRemoting</span><span style="color: #000000">
</span><span style="color: #5f9ea0; font-weight: bold">Enable-WSmanCredSSP</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Role</span><span style="color: #000000"> </span><span style="color: #800000">Server</span><span style="color: #000000">
</span><span style="color: #5f9ea0; font-weight: bold">Set-Item</span><span style="color: #000000"> WSMan:\</span><span style="color: #800000">localhost\Shell\MaxMemoryPerShellMB</span><span style="color: #000000"> </span><span style="color: #000000">1024</span><span style="color: #000000">
</span><span style="color: #5f9ea0; font-weight: bold">Register-PSSessionConfiguration</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Name</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">SharePoint</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-StartupScript</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\sharepoint.ps1</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Force</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ThreadOptions</span><span style="color: #000000"> </span><span style="color: #800000">ReuseThread</span><span style="color: #000000">
</span><span style="color: #5f9ea0; font-weight: bold">Set-PSSessionConfiguration</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Name</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">SharePoint</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ShowSecurityDescriptorUI</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Force</span><span style="color: #000000">
</span></pre>
        </div>
      </li>

      <li>Because the we’re using scripts and because those scripts are stored on a network share we had to set the PowerShell execution policy on each server to Bypass. </li>
    </ul>
  </li>

  <li>SPInstall Permissions 
    <ul>
      <li>The scripts were all run using a single named account which we called SPInstall. In order to perform all the required tasks this account was made a local administrator on all the SharePoint servers (none of the others) and the account was granted the dbcreator and securityadmin roles on SQL01 and SQL02 (or primary and failover SQL instances). </li>
    </ul>
  </li>

  <li>Add SQL Alias and DNS Entries 
    <ul>
      <li>The DNS servers were updated with the appropriate entries for all of our Web Applications (we did not use hosts files) and, to connect to SQL Server, we used a SQL alias which needed to be added on each of the SharePoint servers. </li>
    </ul>
  </li>
</ul>

<h2>Controller Scripts</h2>

<p>So that constitutes the extent of the prep work that we did before we could kick off the scripts that I put together. To do the provisioning I used a main “controller” script which I called <strong>ConfigureServer.ps1</strong>. This script was responsible for loading all the subsequent scripts which created the initial Farm (or connected to it), provisioned the Web Applications and Site Collections, and finally, created all the relevant Service Applications:</p>

<div class="codebox">
  <pre><span style="color: #0000ff">param</span><span style="color: #000000">(
  [</span><span style="color: #008080">switch</span><span style="color: #000000">]</span><span style="color: #800080">$Connect</span><span style="color: #000000">
)

</span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Script Start Time: $(Get-Date)</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ForegroundColor</span><span style="color: #000000"> </span><span style="color: #800000">Green</span><span style="color: #000000">

</span><span style="color: #008000">#</span><span style="color: #008000">Main Farm</span><span style="color: #008000">
</span><span style="color: #000000">. .\FarmCreation\Build-SPFarm.ps1
</span><span style="color: #800080">$farmConfigFile</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Resolve-Path</span><span style="color: #000000"> .\</span><span style="color: #800000">FarmCreation\FarmConfigurations</span><span style="color: #000000">.xml
</span><span style="color: #0000ff">try</span><span style="color: #000000"> {
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$Connect</span><span style="color: #000000">) {
        Join-SPFarm </span><span style="color: #800080">$farmConfigFile</span><span style="color: #000000">
    } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
        New-SPFarm </span><span style="color: #800080">$farmConfigFile</span><span style="color: #000000">
    }
} </span><span style="color: #0000ff">catch</span><span style="color: #000000"> {
    </span><span style="color: #5f9ea0; font-weight: bold">Write-Warning</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Unable to build or join Farm!</span><span style="color: #800000">&quot;</span><span style="color: #000000">
    </span><span style="color: #800080">$_</span><span style="color: #000000">
    </span><span style="color: #0000ff">return</span><span style="color: #000000">
}

</span><span style="color: #008000">#</span><span style="color: #008000">Web Applications</span><span style="color: #008000">
</span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #ff0000">!</span><span style="color: #800080">$Connect</span><span style="color: #000000">) {
    </span><span style="color: #008000">#</span><span style="color: #008000">Only need to do this once so do it when we create the farm initially and not for each connection.</span><span style="color: #008000">
</span><span style="color: #000000">    </span><span style="color: #0000ff">try</span><span style="color: #000000"> {
        . .\WebApplications\Provision-WebApplications.ps1
        Provision-WebApplications (</span><span style="color: #5f9ea0; font-weight: bold">Resolve-Path</span><span style="color: #000000"> .\</span><span style="color: #800000">WebApplications\WebApplications</span><span style="color: #000000">.xml)
    } </span><span style="color: #0000ff">catch</span><span style="color: #000000"> {
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Warning</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Unable to create web applications!</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #800080">$_</span><span style="color: #000000">
        </span><span style="color: #0000ff">return</span><span style="color: #000000">
    }
}

</span><span style="color: #008000">#</span><span style="color: #008000">Services</span><span style="color: #008000">
</span><span style="color: #0000ff">try</span><span style="color: #000000"> {
    </span><span style="color: #008000">#</span><span style="color: #008000">State Service</span><span style="color: #008000">
</span><span style="color: #000000">    . .\ServiceApplications\StateServices\Start-StateServices.ps1
    Start-StateServices (</span><span style="color: #5f9ea0; font-weight: bold">Resolve-Path</span><span style="color: #000000"> .\</span><span style="color: #800000">ServiceApplications\StateServices\StateServices</span><span style="color: #000000">.xml)

    </span><span style="color: #008000">#</span><span style="color: #008000">Usage Service</span><span style="color: #008000">
</span><span style="color: #000000">    . .\ServiceApplications\UsageService\Start-UsageService.ps1
    Start-UsageService (</span><span style="color: #5f9ea0; font-weight: bold">Resolve-Path</span><span style="color: #000000"> .\</span><span style="color: #800000">ServiceApplications\UsageService\UsageService</span><span style="color: #000000">.xml)

    </span><span style="color: #008000">#</span><span style="color: #008000">Secure Store Services</span><span style="color: #008000">
</span><span style="color: #000000">    . .\ServiceApplications\SecureStoreServices\Start-SecureStoreServices.ps1
    Start-SecureStoreServices (</span><span style="color: #5f9ea0; font-weight: bold">Resolve-Path</span><span style="color: #000000"> .\</span><span style="color: #800000">ServiceApplications\SecureStoreServices\SecureStoreServices</span><span style="color: #000000">.xml)

    </span><span style="color: #008000">#</span><span style="color: #008000">Web Analytics Services</span><span style="color: #008000">
</span><span style="color: #000000">    . .\ServiceApplications\WebAnalyticsServices\Start-WebAnalyticsServices.ps1
    Start-WebAnalyticsServices (</span><span style="color: #5f9ea0; font-weight: bold">Resolve-Path</span><span style="color: #000000"> .\</span><span style="color: #800000">ServiceApplications\WebAnalyticsServices\WebAnalyticsServices</span><span style="color: #000000">.xml)

    </span><span style="color: #008000">#</span><span style="color: #008000">User Code Services</span><span style="color: #008000">
</span><span style="color: #000000">    . .\ServiceApplications\UserCodeServices\Start-UserCodeServices.ps1
    Start-UserCodeServices (</span><span style="color: #5f9ea0; font-weight: bold">Resolve-Path</span><span style="color: #000000"> .\</span><span style="color: #800000">ServiceApplications\UserCodeServices\UserCodeServices</span><span style="color: #000000">.xml)

    </span><span style="color: #008000">#</span><span style="color: #008000">BCS Services</span><span style="color: #008000">
</span><span style="color: #000000">    . .\ServiceApplications\BCSServices\Start-BCSServices.ps1
    Start-BCSServices (</span><span style="color: #5f9ea0; font-weight: bold">Resolve-Path</span><span style="color: #000000"> .\</span><span style="color: #800000">ServiceApplications\BCSServices\BCSServices</span><span style="color: #000000">.xml)

    </span><span style="color: #008000">#</span><span style="color: #008000">Excel Services</span><span style="color: #008000">
</span><span style="color: #000000">    . .\ServiceApplications\ExcelServices\Start-ExcelServices.ps1
    Start-ExcelServices (</span><span style="color: #5f9ea0; font-weight: bold">Resolve-Path</span><span style="color: #000000"> .\</span><span style="color: #800000">ServiceApplications\ExcelServices\ExcelServices</span><span style="color: #000000">.xml)

    </span><span style="color: #008000">#</span><span style="color: #008000">Word Automation Services</span><span style="color: #008000">
</span><span style="color: #000000">    . .\ServiceApplications\WordAutomationServices\Start-WordAutomationServices.ps1
    Start-WordAutomationServices (</span><span style="color: #5f9ea0; font-weight: bold">Resolve-Path</span><span style="color: #000000"> .\</span><span style="color: #800000">ServiceApplications\WordAutomationServices\WordAutomationServices</span><span style="color: #000000">.xml)

    </span><span style="color: #008000">#</span><span style="color: #008000">Metadata Services</span><span style="color: #008000">
</span><span style="color: #000000">    . .\ServiceApplications\MetadataServices\Start-MetadataServices.ps1
    Start-MetadataServices (</span><span style="color: #5f9ea0; font-weight: bold">Resolve-Path</span><span style="color: #000000"> .\</span><span style="color: #800000">ServiceApplications\MetadataServices\MetadataServices</span><span style="color: #000000">.xml)

    </span><span style="color: #008000">#</span><span style="color: #008000">C2WTS</span><span style="color: #008000">
</span><span style="color: #000000">    . .\ServiceApplications\ClaimsToWindowsTokenServices\Start-ClaimsToWindowsTokenServices.ps1
    Start-ClaimsToWindowsTokenServices (</span><span style="color: #5f9ea0; font-weight: bold">Resolve-Path</span><span style="color: #000000"> .\</span><span style="color: #800000">ServiceApplications\ClaimsToWindowsTokenServices\ClaimsToWindowsTokenServices</span><span style="color: #000000">.xml)

    </span><span style="color: #008000">#</span><span style="color: #008000">PowerPoint Services</span><span style="color: #008000">
</span><span style="color: #000000">    . .\ServiceApplications\PowerPointServices\Start-PowerPointServices.ps1
    Start-PowerPointServices (</span><span style="color: #5f9ea0; font-weight: bold">Resolve-Path</span><span style="color: #000000"> .\</span><span style="color: #800000">ServiceApplications\PowerPointServices\PowerPointServices</span><span style="color: #000000">.xml)

    </span><span style="color: #008000">#</span><span style="color: #008000">Word Viewing Services</span><span style="color: #008000">
</span><span style="color: #000000">    . .\ServiceApplications\WordViewingServices\Start-WordViewingServices.ps1
    Start-WordViewingServices (</span><span style="color: #5f9ea0; font-weight: bold">Resolve-Path</span><span style="color: #000000"> .\</span><span style="color: #800000">ServiceApplications\WordViewingServices\WordViewingServices</span><span style="color: #000000">.xml)
    
    </span><span style="color: #008000">#</span><span style="color: #008000">User Profile Services</span><span style="color: #008000">
</span><span style="color: #000000">    . .\ServiceApplications\UserProfileServices\Start-UserProfileServices.ps1
    Start-UserProfileServices (</span><span style="color: #5f9ea0; font-weight: bold">Resolve-Path</span><span style="color: #000000"> .\</span><span style="color: #800000">ServiceApplications\UserProfileServices\UserProfileServices</span><span style="color: #000000">.xml)

    </span><span style="color: #008000">#</span><span style="color: #008000">Enterprise Search Services</span><span style="color: #008000">
</span><span style="color: #000000">    . .\ServiceApplications\EnterpriseSearchServices\Start-EnterpriseSearchServices.ps1
    Start-EnterpriseSearchServices (</span><span style="color: #5f9ea0; font-weight: bold">Resolve-Path</span><span style="color: #000000"> .\</span><span style="color: #800000">ServiceApplications\EnterpriseSearchServices\EnterpriseSearchServices</span><span style="color: #000000">.xml)

} </span><span style="color: #0000ff">catch</span><span style="color: #000000"> {
    </span><span style="color: #5f9ea0; font-weight: bold">Write-Warning</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Service Application creation failed!</span><span style="color: #800000">&quot;</span><span style="color: #000000">
    </span><span style="color: #800080">$_</span><span style="color: #000000">
    </span><span style="color: #0000ff">return</span><span style="color: #000000">
}
</span><span style="color: #0000ff">finally</span><span style="color: #000000"> {
    </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Script End Time: $(Get-Date)</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ForegroundColor</span><span style="color: #000000"> </span><span style="color: #800000">Green</span><span style="color: #000000">
}</span></pre>
</div>

<p>&#160;</p>

<p>This script was executed on each server, however, we ran it first on SP03 which is where the User Profile Synchronization Service was to be run. Due to issues with getting this guy to work using remoting we chose to RDP directly into the server and run this one script while logged into the server. Once this server was configured and the initial Farm created then we’d go ahead and run the script on the remaining servers by using PowerShell remoting to execute the script from a single location.</p>

<p>This is the script, which I named simply <strong>go.ps1</strong>, that I used to call the <em>ConfigureServer.ps1</em> script for all the remaining SharePoint servers (everything other than SP03):</p>

<div style="height: auto" class="codebox">
  <pre><span style="color: #800080">$servers</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> @(</span><span style="color: #800000">&quot;</span><span style="color: #800000">SP01</span><span style="color: #800000">&quot;</span><span style="color: #000000">,</span><span style="color: #800000">&quot;</span><span style="color: #800000">SP02</span><span style="color: #800000">&quot;</span><span style="color: #000000">,</span><span style="color: #800000">&quot;</span><span style="color: #800000">SP04</span><span style="color: #800000">&quot;</span><span style="color: #000000">,</span><span style="color: #800000">&quot;</span><span style="color: #800000">SP05</span><span style="color: #800000">&quot;</span><span style="color: #000000">,</span><span style="color: #800000">&quot;</span><span style="color: #800000">SP06</span><span style="color: #800000">&quot;</span><span style="color: #000000">)
</span><span style="color: #800080">$cred</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-Credential</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">isclondon\spinstall</span><span style="color: #800000">&quot;</span><span style="color: #000000">

</span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (</span><span style="color: #800080">$server</span><span style="color: #000000"> </span><span style="color: #0000ff">in</span><span style="color: #000000"> </span><span style="color: #800080">$servers</span><span style="color: #000000">) {
    </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">---------------------------------------------------------------</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ForegroundColor</span><span style="color: #000000"> </span><span style="color: #800000">Green</span><span style="color: #000000">
    </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">$(Get-Date): Connecting to server $server.</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ForegroundColor</span><span style="color: #000000"> </span><span style="color: #800000">Green</span><span style="color: #000000">
    </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">---------------------------------------------------------------</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ForegroundColor</span><span style="color: #000000"> </span><span style="color: #800000">Green</span><span style="color: #000000">
    </span><span style="color: #800080">$session</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-PSSession</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ComputerName</span><span style="color: #000000"> </span><span style="color: #800080">$server</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Authentication</span><span style="color: #000000"> </span><span style="color: #800000">CredSSP</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Credential</span><span style="color: #000000"> </span><span style="color: #800080">$cred</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ConfigurationName</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">SharePoint</span><span style="color: #800000">&quot;</span><span style="color: #000000">
    </span><span style="color: #5f9ea0; font-weight: bold">Invoke-Command</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Session</span><span style="color: #000000"> </span><span style="color: #800080">$session</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ScriptBlock</span><span style="color: #000000"> {</span><span style="color: #5f9ea0; font-weight: bold">Set-ExecutionPolicy</span><span style="color: #000000"> </span><span style="color: #800000">Bypass</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Scope</span><span style="color: #000000"> </span><span style="color: #0000ff">Process</span><span style="color: #000000">}
    </span><span style="color: #5f9ea0; font-weight: bold">Invoke-Command</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Session</span><span style="color: #000000"> </span><span style="color: #800080">$session</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ScriptBlock</span><span style="color: #000000"> {</span><span style="color: #5f9ea0; font-weight: bold">cd</span><span style="color: #000000"> </span><span style="color: #800000">\\sp03\c$\Scripts}</span><span style="color: #000000">
    </span><span style="color: #5f9ea0; font-weight: bold">Invoke-Command</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Session</span><span style="color: #000000"> </span><span style="color: #800080">$session</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ScriptBlock</span><span style="color: #000000"> {. .\ConfigureServer.ps1 -Connect}
    </span><span style="color: #5f9ea0; font-weight: bold">Remove-PSSession</span><span style="color: #000000"> </span><span style="color: #800080">$session</span><span style="color: #000000">
    </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">$(Get-Date): Finished for server $server</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ForegroundColor</span><span style="color: #000000"> </span><span style="color: #800000">Green</span><span style="color: #000000">
}</span></pre>
</div>

<p>&#160;</p>

<h2>Build-SPFarm.ps1</h2>

<p>So the preceding two scripts constitute the “controller” scripts that I used to call out to the core scripts which did all the real work. Now let’s look at the first and most important script as it is responsible for creating the Farm (or connecting to the Farm): <strong>Build-SPFarm.ps1</strong>.</p>

<p>This script, like all the remaining scripts is driven via an XML file; in other words, I store all the configuration information in a series of XML files that I pass into the function contained within the script. By taking this approach I can write a single script which is not tied to any particular environment and only change the contents of the XML file.</p>

<blockquote>
  <p>I think something that a lot of people forget when writing PowerShell scripts is that you are writing code, and just as you would never deploy code written by any old developer to your production environment without it first going through proper testing in a test environment, so should you never deploy (or execute in this case) scripts to production without first testing those scripts. And, with any code, if you make changes to that code you should follow proper testing practices and do a full regression test of any code that was modified (yes, this includes changing variable values because the value you specify could actually break the script if improperly formatted – think of someone forgetting a closing quote or adding a special character to the contents of a string variable). For these reasons, and many others, I encourage people to reduce the changes made to scripts by pulling the configuration information out into an XML file.</p>
</blockquote>

<p>So lets look at the <strong>FarmConfigurations.xml</strong> XML file that I used for the <em>Build-SPFarm.ps1</em> script:</p>

<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Farm</span> <span class="attr">ConfigDB</span><span class="kwrd">=&quot;ISC_Config&quot;</span>
      <span class="attr">ConfigDBFailoverDatabaseServer</span><span class="kwrd">=&quot;&quot;</span>
      <span class="attr">AdminContentDB</span><span class="kwrd">=&quot;ISC_Content_CentralAdmin&quot;</span> 
      <span class="attr">AdminContentDBFailoverDatabaseServer</span><span class="kwrd">=&quot;&quot;</span>
      <span class="attr">DatabaseServer</span><span class="kwrd">=&quot;ISCSharePoint1&quot;</span> 
      <span class="attr">Passphrase</span><span class="kwrd">=&quot;p@ssw0rd&quot;</span>
      <span class="attr">OutgoingEmailServer</span><span class="kwrd">=&quot;192.168.1.101&quot;</span>
      <span class="attr">OutgoingEmailFromAddr</span><span class="kwrd">=&quot;administrator@isclondon.com&quot;</span>
      <span class="attr">OutgoingEmailReplyToAddr</span><span class="kwrd">=&quot;administrator@isclondon.com&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">FarmAccount</span> <span class="attr">AccountName</span><span class="kwrd">=&quot;isclondon\spfarm&quot;</span> <span class="attr">AccountPassword</span><span class="kwrd">=&quot;password&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">CentralAdmin</span> <span class="attr">Port</span><span class="kwrd">=&quot;2010&quot;</span> <span class="attr">AuthProvider</span><span class="kwrd">=&quot;NTLM&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Servers</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Server</span> <span class="attr">Name</span><span class="kwrd">=&quot;SP01&quot;</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Server</span> <span class="attr">Name</span><span class="kwrd">=&quot;SP02&quot;</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Server</span> <span class="attr">Name</span><span class="kwrd">=&quot;SP03&quot;</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Servers</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">CentralAdmin</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Services</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">WebApplicationService</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Servers</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">Server</span> <span class="attr">Name</span><span class="kwrd">=&quot;SP01&quot;</span> <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">Server</span> <span class="attr">Name</span><span class="kwrd">=&quot;SP02&quot;</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">Servers</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">WebApplicationService</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">WorkflowTimerService</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Servers</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">Server</span> <span class="attr">Name</span><span class="kwrd">=&quot;SP01&quot;</span> <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">Server</span> <span class="attr">Name</span><span class="kwrd">=&quot;SP02&quot;</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">Servers</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">WorkflowTimerService</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">IncomingEmailService</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Servers</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">Server</span> <span class="attr">Name</span><span class="kwrd">=&quot;SP01&quot;</span> <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">Server</span> <span class="attr">Name</span><span class="kwrd">=&quot;SP02&quot;</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">Servers</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">IncomingEmailService</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">TraceService</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Account</span> <span class="attr">AccountName</span><span class="kwrd">=&quot;isclondon\sptrace&quot;</span> <span class="attr">AccountPassword</span><span class="kwrd">=&quot;password&quot;</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">TraceService</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Services</span><span class="kwrd">&gt;</span>
 <span class="kwrd">&lt;/</span><span class="html">Farm</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">





.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>&#160;</p>

<p>Note that in this XML we’ve embedded the passwords used – I don’t actually recommend doing this, but if you do you should make sure the files are properly secured and, ideally, remove the password after provisioning is complete (we embedded the passwords so that we wouldn’t be continually prompted for credentials during the build as this would make it very difficult to talk through our presentation).</p>

<p>Before I show the contents of the <em>Build-SPFarm.ps1</em> script I just wanted to point out one more design consideration which you may have clued in on by looking at the <em>ConfigureServer.ps1</em> script. With rare exceptions (the <em>ConfigureServer.ps1</em> script being one of them), I always make my scripts so that running the script will actually do nothing other than load a function in memory which must then be called in order to perform any action. This is to prevent someone from accidentally causing a script to execute (for example, you intend to edit the file so you double-click it and rather than open in an editor it opens in the console and is executed). The only reason the <em>ConfigureServer.ps1 </em>script does not work this way is because I wanted to show that you can pass parameters into a script file.</p>

<p>With that out of the way, let’s look at the <em>Build-SPFarm.ps1</em> script:</p>

<div class="codebox">
  <pre><span style="color: #0000ff">function</span><span style="color: #000000"> Join-SPFarm ([</span><span style="color: #008080">string</span><span style="color: #000000">]</span><span style="color: #800080">$settings</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> $(</span><span style="color: #0000ff">throw</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">-settings is required</span><span style="color: #800000">&quot;</span><span style="color: #000000">)) {
    Build-SPFarm </span><span style="color: #800080">$true</span><span style="color: #000000"> </span><span style="color: #800080">$settings</span><span style="color: #000000">
}

</span><span style="color: #0000ff">function</span><span style="color: #000000"> New-SPFarm ([</span><span style="color: #008080">string</span><span style="color: #000000">]</span><span style="color: #800080">$settings</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> $(</span><span style="color: #0000ff">throw</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">-settings is required</span><span style="color: #800000">&quot;</span><span style="color: #000000">)) {
    Build-SPFarm </span><span style="color: #800080">$false</span><span style="color: #000000"> </span><span style="color: #800080">$settings</span><span style="color: #000000">
}

</span><span style="color: #0000ff">function</span><span style="color: #000000"> Build-SPFarm ([</span><span style="color: #008080">bool</span><span style="color: #000000">]</span><span style="color: #800080">$connectToExisting</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$false</span><span style="color: #000000">, [</span><span style="color: #008080">string</span><span style="color: #000000">]</span><span style="color: #800080">$settings</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> $(</span><span style="color: #0000ff">throw</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">-settings is required</span><span style="color: #800000">&quot;</span><span style="color: #000000">)) {   
    [</span><span style="color: #008080">xml</span><span style="color: #000000">]</span><span style="color: #800080">$config</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-Content</span><span style="color: #000000"> </span><span style="color: #800080">$settings</span><span style="color: #000000">

    </span><span style="color: #0000ff">if</span><span style="color: #000000"> ([</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.FarmAccount.AccountPassword)) {
        </span><span style="color: #800080">$farmAcct</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-Credential</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.FarmAccount.AccountName
    } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
        </span><span style="color: #800080">$farmAcct</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-Object</span><span style="color: #000000"> </span><span style="color: #800000">System.Management.Automation.PSCredential</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.FarmAccount.AccountName, (</span><span style="color: #5f9ea0; font-weight: bold">ConvertTo-SecureString</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.FarmAccount.AccountPassword </span><span style="font-style: italic; color: #5f9ea0">-AsPlainText</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-force</span><span style="color: #000000">)
    }

    </span><span style="color: #800080">$configDb</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.ConfigDB
    </span><span style="color: #800080">$contentDB</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.AdminContentDb
    </span><span style="color: #800080">$server</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.DatabaseServer
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.Passphrase.Length </span><span style="color: #ff0000">-gt</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">) {
        </span><span style="color: #800080">$passphrase</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> (</span><span style="color: #5f9ea0; font-weight: bold">ConvertTo-SecureString</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.Passphrase </span><span style="font-style: italic; color: #5f9ea0">-AsPlainText</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-force</span><span style="color: #000000">)
    } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Warning</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Using the Farm Admin's password for a passphrase</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #800080">$passphrase</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$farmAcct</span><span style="color: #000000">.Password
    }
    
    </span><span style="color: #008000">#</span><span style="color: #008000">Only build the farm if we don't currently have a farm created</span><span style="color: #008000">
</span><span style="color: #000000">    </span><span style="color: #0000ff">if</span><span style="color: #000000"> ([</span><span style="color: #008080">Microsoft.SharePoint.Administration.SPFarm</span><span style="color: #000000">]::</span><span style="color: #8b4513">Local</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
        psconfig -cmd upgrade -inplace b2b
        
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$connectToExisting</span><span style="color: #000000">) {
            </span><span style="color: #008000">#</span><span style="color: #008000">Connecting to farm</span><span style="color: #008000">
</span><span style="color: #000000">            </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Connecting to Farm...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            </span><span style="color: #5f9ea0; font-weight: bold">Connect-SPConfigurationDatabase</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-DatabaseName</span><span style="color: #000000"> </span><span style="color: #800080">$configDb</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-DatabaseServer</span><span style="color: #000000"> </span><span style="color: #800080">$server</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Passphrase</span><span style="color: #000000"> </span><span style="color: #800080">$passphrase</span><span style="color: #000000">
        } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
            </span><span style="color: #008000">#</span><span style="color: #008000">Creating new farm</span><span style="color: #008000">
</span><span style="color: #000000">            </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Creating Farm...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            </span><span style="color: #5f9ea0; font-weight: bold">New-SPConfigurationDatabase</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-DatabaseName</span><span style="color: #000000"> </span><span style="color: #800080">$configDb</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-DatabaseServer</span><span style="color: #000000"> </span><span style="color: #800080">$server</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-AdministrationContentDatabaseName</span><span style="color: #000000"> </span><span style="color: #800080">$contentDB</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-Passphrase</span><span style="color: #000000"> </span><span style="color: #800080">$passphrase</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-FarmCredentials</span><span style="color: #000000"> </span><span style="color: #800080">$farmAcct</span><span style="color: #000000">
            
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.ConfigDBFailoverDatabaseServer)) {
                Set-FailoverDatabase </span><span style="color: #800080">$configDb</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.ConfigDBFailoverDatabaseServer
            }
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.AdminContentDBFailoverDatabaseServer)) {
                Set-FailoverDatabase </span><span style="color: #800080">$contentDB</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.AdminContentDBFailoverDatabaseServer
            }
        }
        </span><span style="color: #008000">#</span><span style="color: #008000">Verifying farm creation</span><span style="color: #008000">
</span><span style="color: #000000">        </span><span style="color: #800080">$spfarm</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPFarm</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000">
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$spfarm</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
            </span><span style="color: #0000ff">throw</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Unable to verify farm creation.</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        }

        </span><span style="color: #008000">#</span><span style="color: #008000">ACLing SharePoint Resources</span><span style="color: #008000">
</span><span style="color: #000000">        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Calling Initialize-SPResourceSecurity...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #5f9ea0; font-weight: bold">Initialize-SPResourceSecurity</span><span style="color: #000000">

        </span><span style="color: #008000">#</span><span style="color: #008000">Installing Services</span><span style="color: #008000">
</span><span style="color: #000000">        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Calling Install-SPService...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #5f9ea0; font-weight: bold">Install-SPService</span><span style="color: #000000">

        </span><span style="color: #008000">#</span><span style="color: #008000">Installing Features</span><span style="color: #008000">
</span><span style="color: #000000">        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Calling Install-SPFeature...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #5f9ea0; font-weight: bold">Install-SPFeature</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-AllExistingFeatures</span><span style="color: #000000">
        
        </span><span style="color: #5f9ea0; font-weight: bold">Remove-PsSnapin</span><span style="color: #000000"> </span><span style="color: #800000">Microsoft.SharePoint.PowerShell</span><span style="color: #000000">
        </span><span style="color: #5f9ea0; font-weight: bold">Add-PsSnapin</span><span style="color: #000000"> </span><span style="color: #800000">Microsoft.SharePoint.PowerShell</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000">
    } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Warning</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Farm exists. Skipping creation.</span><span style="color: #800000">&quot;</span><span style="color: #000000">
    }
    
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> ((</span><span style="color: #5f9ea0; font-weight: bold">Get-Service</span><span style="color: #000000"> </span><span style="color: #800000">sptimerv4</span><span style="color: #000000">).Status </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Running</span><span style="color: #800000">&quot;</span><span style="color: #000000">) {
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Starting SPTimerV4 Service</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #5f9ea0; font-weight: bold">Start-Service</span><span style="color: #000000"> </span><span style="color: #800000">sptimerv4</span><span style="color: #000000">
    }

    </span><span style="color: #800080">$scaConfig</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.CentralAdmin
    </span><span style="color: #800080">$installSCA</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> ((</span><span style="color: #800080">$scaConfig</span><span style="color: #000000">.Servers.Server | </span><span style="color: #5f9ea0; font-weight: bold">where</span><span style="color: #000000"> {</span><span style="color: #800080">$_</span><span style="color: #000000">.Name </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$env:computername</span><span style="color: #000000">}) </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">)
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$installSCA</span><span style="color: #000000">) {
        </span><span style="color: #800080">$auth</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$scaConfig</span><span style="color: #000000">.AuthProvider
        </span><span style="color: #800080">$port</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$scaConfig</span><span style="color: #000000">.Port
        </span><span style="color: #800080">$url</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">http://$($env:computername):$port</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #800080">$sca</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> [</span><span style="color: #008080">Microsoft.SharePoint.Administration.SPWebApplication</span><span style="color: #000000">]::</span><span style="color: #8b4513">Lookup</span><span style="color: #000000">(</span><span style="color: #800080">$url</span><span style="color: #000000">)
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$installSCA</span><span style="color: #000000"> </span><span style="color: #ff0000">-and</span><span style="color: #000000"> </span><span style="color: #800080">$sca</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
            </span><span style="color: #008000">#</span><span style="color: #008000">Provisioning Central Administration</span><span style="color: #008000">
</span><span style="color: #000000">            </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Creating Central Admin Site at $url...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            </span><span style="color: #5f9ea0; font-weight: bold">New-SPCentralAdministration</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Port</span><span style="color: #000000"> </span><span style="color: #800080">$port</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-WindowsAuthProvider</span><span style="color: #000000"> </span><span style="color: #800080">$auth</span><span style="color: #000000">

            </span><span style="color: #008000">#</span><span style="color: #008000">Installing Help</span><span style="color: #008000">
</span><span style="color: #000000">            </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Calling Install-SPHelpCollection...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            </span><span style="color: #5f9ea0; font-weight: bold">Install-SPHelpCollection</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-All</span><span style="color: #000000">

            </span><span style="color: #008000">#</span><span style="color: #008000">Installing Application Content</span><span style="color: #008000">
</span><span style="color: #000000">            </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Calling Install-SPApplicationContent...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            </span><span style="color: #5f9ea0; font-weight: bold">Install-SPApplicationContent</span><span style="color: #000000">
        }
    }
    
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #ff0000">!</span><span style="color: #800080">$connectToExisting</span><span style="color: #000000">) {
        </span><span style="color: #800080">$server</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.OutgoingEmailServer
        </span><span style="color: #800080">$from</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.OutgoingEmailFromAddr
        </span><span style="color: #800080">$replyTo</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.OutgoingEmailReplyToAddr
        </span><span style="color: #800080">$charSet</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #000000">65001</span><span style="color: #000000">
        </span><span style="color: #800080">$wa</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> [</span><span style="color: #008080">Microsoft.SharePoint.Administration.SPAdministrationWebApplication</span><span style="color: #000000">]::</span><span style="color: #8b4513">Local</span><span style="color: #000000">
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$wa</span><span style="color: #000000"> </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
            </span><span style="color: #800080">$wa</span><span style="color: #000000">.UpdateMailSettings(</span><span style="color: #800080">$server</span><span style="color: #000000">, </span><span style="color: #800080">$from</span><span style="color: #000000">, </span><span style="color: #800080">$replyTo</span><span style="color: #000000">, </span><span style="color: #800080">$charSet</span><span style="color: #000000">)
        }
    }
    
    </span><span style="color: #008000">#</span><span style="color: #008000">Stop or Start key service instances</span><span style="color: #008000">
</span><span style="color: #000000">    </span><span style="color: #800080">$startWebAppSvc</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> ((</span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.Services.WebApplicationService.Servers.Server | </span><span style="color: #5f9ea0; font-weight: bold">where</span><span style="color: #000000"> {</span><span style="color: #800080">$_</span><span style="color: #000000">.Name </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$env:computername</span><span style="color: #000000">}) </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">)
    Set-ServiceInstanceState </span><span style="color: #800000">&quot;</span><span style="color: #800000">Microsoft SharePoint Foundation Web Application</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="color: #800080">$startWebAppSvc</span><span style="color: #000000">

    </span><span style="color: #800080">$startWorkflowSvc</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> ((</span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.Services.WorkflowTimerService.Servers.Server | </span><span style="color: #5f9ea0; font-weight: bold">where</span><span style="color: #000000"> {</span><span style="color: #800080">$_</span><span style="color: #000000">.Name </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$env:computername</span><span style="color: #000000">}) </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">)
    Set-ServiceInstanceState </span><span style="color: #800000">&quot;</span><span style="color: #800000">Microsoft SharePoint Foundation Workflow Timer Service</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="color: #800080">$startWorkflowSvc</span><span style="color: #000000">

    </span><span style="color: #800080">$startIncomingEmailSvc</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> ((</span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.Services.IncomingEmailService.Servers.Server | </span><span style="color: #5f9ea0; font-weight: bold">where</span><span style="color: #000000"> {</span><span style="color: #800080">$_</span><span style="color: #000000">.Name </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$env:computername</span><span style="color: #000000">}) </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">)
    Set-ServiceInstanceState </span><span style="color: #800000">&quot;</span><span style="color: #800000">Microsoft SharePoint Foundation Incoming E-Mail</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="color: #800080">$startIncomingEmailSvc</span><span style="color: #000000">
    
    
    </span><span style="color: #008000">#</span><span style="color: #008000">Set SPTraceV4 to run as domain account</span><span style="color: #008000">
</span><span style="color: #000000">    </span><span style="color: #800080">$accountNode</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.Services.TraceService.Account
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$accountNode</span><span style="color: #000000"> </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000"> </span><span style="color: #ff0000">-and</span><span style="color: #000000"> ![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$accountNode</span><span style="color: #000000">.AccountName)) {
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> ([</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$accountNode</span><span style="color: #000000">.AccountPassword)) {
            </span><span style="color: #800080">$svcAccount</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-Credential</span><span style="color: #000000"> </span><span style="color: #800080">$accountNode</span><span style="color: #000000">.AccountName
        } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
            </span><span style="color: #800080">$svcAccount</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-Object</span><span style="color: #000000"> </span><span style="color: #800000">System.Management.Automation.PSCredential</span><span style="color: #000000"> </span><span style="color: #800080">$accountNode</span><span style="color: #000000">.AccountName, (</span><span style="color: #5f9ea0; font-weight: bold">ConvertTo-SecureString</span><span style="color: #000000"> </span><span style="color: #800080">$accountNode</span><span style="color: #000000">.AccountPassword </span><span style="font-style: italic; color: #5f9ea0">-AsPlainText</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-force</span><span style="color: #000000">)
        }
        </span><span style="color: #800080">$user</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPManagedAccount</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Identity</span><span style="color: #000000"> </span><span style="color: #800080">$svcAccount</span><span style="color: #000000">.Username </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000">
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$user</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
            </span><span style="color: #800080">$user</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-SPManagedAccount</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Credential</span><span style="color: #000000"> </span><span style="color: #800080">$svcAccount</span><span style="color: #000000">
        }
        </span><span style="color: #800080">$tracingSvc</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> (</span><span style="color: #5f9ea0; font-weight: bold">Get-SPFarm</span><span style="color: #000000">).Services | ? {</span><span style="color: #800080">$_</span><span style="color: #000000">.Name </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">SPTraceV4</span><span style="color: #800000">&quot;</span><span style="color: #000000">}
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$tracingSvc</span><span style="color: #000000">.ProcessIdentity.Username </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$user</span><span style="color: #000000">.Username) {
            </span><span style="color: #800080">$tracingSvc</span><span style="color: #000000">.ProcessIdentity.ManagedAccount </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$user</span><span style="color: #000000">
            </span><span style="color: #800080">$tracingSvc</span><span style="color: #000000">.ProcessIdentity.CurrentIdentityType </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">SpecificUser</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            </span><span style="color: #800080">$tracingSvc</span><span style="color: #000000">.ProcessIdentity.Update()
            </span><span style="color: #800080">$tracingSvc</span><span style="color: #000000">.ProcessIdentity.Deploy()
        }
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Adding `&quot;$($user.Username)`&quot; to Performance Log Users group...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #800080">$p</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Start-Process</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-PassThru</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-FilePath</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">c:\windows\system32\net.exe</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ArgumentList</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">localgroup `&quot;Performance Log Users`&quot; `&quot;$($user.Username)`&quot; /add</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Wait</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-NoNewWindow</span><span style="color: #000000">
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$p</span><span style="color: #000000">.ExitCode </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">) { 
            </span><span style="color: #5f9ea0; font-weight: bold">Write-Warning</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Unable to add `&quot;$($user.Username)`&quot; to Performance Log Users group!</span><span style="color: #800000">&quot;</span><span style="color: #000000"> 
        } </span><span style="color: #0000ff">else</span><span style="color: #000000"> { 
            </span><span style="color: #5f9ea0; font-weight: bold">Restart-Service</span><span style="color: #000000"> </span><span style="color: #800000">SPTraceV4</span><span style="color: #000000">
            iisreset
        }
    }

} 
</span><span style="color: #0000ff">function</span><span style="color: #000000"> </span><span style="color: #5f9ea0">Set-ServiceInstanceState</span><span style="color: #000000">(</span><span style="color: #800080">$typeName</span><span style="color: #000000">, </span><span style="color: #800080">$enable</span><span style="color: #000000">) {
    </span><span style="color: #800080">$svc</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPServiceInstance</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Server</span><span style="color: #000000"> </span><span style="color: #800080">$env:computername</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">where</span><span style="color: #000000"> {</span><span style="color: #800080">$_</span><span style="color: #000000">.TypeName </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$typeName</span><span style="color: #000000">}
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$svc</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
        </span><span style="color: #0000ff">throw</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Unable to retrieve $typeName Service Instance.</span><span style="color: #800000">&quot;</span><span style="color: #000000">
    }
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$svc</span><span style="color: #000000">.Status </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Online</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="color: #ff0000">-and</span><span style="color: #000000"> </span><span style="color: #800080">$enable</span><span style="color: #000000">) {
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Starting $typeName service instance...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #800080">$svc</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">Start-SPServiceInstance</span><span style="color: #000000">
    }
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$svc</span><span style="color: #000000">.Status </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Online</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="color: #ff0000">-and</span><span style="color: #000000"> </span><span style="color: #ff0000">!</span><span style="color: #800080">$enable</span><span style="color: #000000">) {
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Stopping $typeName service instance...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #800080">$svc</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">Stop-SPServiceInstance</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Confirm</span><span style="color: #000000">:</span><span style="color: #800080">$false</span><span style="color: #000000">
    }
}

</span><span style="color: #0000ff">function</span><span style="color: #000000"> </span><span style="color: #5f9ea0">Set-FailoverDatabase</span><span style="color: #000000">(</span><span style="color: #800080">$databaseName</span><span style="color: #000000">, [</span><span style="color: #008080">string</span><span style="color: #000000">]</span><span style="color: #800080">$failoverDbServer</span><span style="color: #000000">) {
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$failoverDbServer</span><span style="color: #000000">)) {
        </span><span style="color: #800080">$db</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPDatabase</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">where</span><span style="color: #000000"> {</span><span style="color: #800080">$_</span><span style="color: #000000">.Name </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$databaseName</span><span style="color: #000000">}
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$db</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) { 
            </span><span style="color: #0000ff">throw</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Unable to retrieve the database to set the failover server: $databaseName</span><span style="color: #800000">&quot;</span><span style="color: #000000"> 
        }
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> ((</span><span style="color: #800080">$db</span><span style="color: #000000">.FailoverServiceInstance </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) </span><span style="color: #ff0000">-or</span><span style="color: #000000"> ![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">Equals</span><span style="color: #000000">(</span><span style="color: #800080">$db</span><span style="color: #000000">.FailoverServiceInstance.NormalizedDataSource, </span><span style="color: #800080">$failoverDbServer</span><span style="color: #000000">, [</span><span style="color: #008080">StringComparison</span><span style="color: #000000">]::</span><span style="color: #8b4513">OrdinalIgnoreCase</span><span style="color: #000000">)) {
            </span><span style="color: #0000ff">try</span><span style="color: #000000"> {
                </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Adding failover database instance...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
                </span><span style="color: #800080">$db</span><span style="color: #000000">.AddFailoverServiceInstance(</span><span style="color: #800080">$failoverDbServer</span><span style="color: #000000">)
                </span><span style="color: #800080">$db</span><span style="color: #000000">.Update()
            } </span><span style="color: #0000ff">catch</span><span style="color: #000000"> {
                </span><span style="color: #5f9ea0; font-weight: bold">Write-Warning</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Unable to set failover database server. $_</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            }
        }
    }
}
</span></pre>
</div>

<p>&#160;</p>

<p>I honestly don’t have the time to explain everything that this script is doing but suffice it to say it is doing a bit more than just creating or connecting to the Farm. One thing in particular is that I chose to put the enabling and disabling of some of the simple services (Web Application, Workflow, and Incoming Email) in this script rather than in the script(s) that provision the Service Applications (this was really just a decision of convenience for me and in my personal scripts this stuff is stored elsewhere).</p>

<p>One other thing I wanted to highlight was this line within the script: “psconfig -cmd upgrade -inplace b2b”. The reason this is there is because we installed the Office Web Applications which incorrectly sets a registry key that indicates that an upgrade is required. We can either fix the registry key or simply open and then close the configuration wizard on each server (without actually letting the wizard run) or we can just run this command on each server just prior to calling the <em>New-SPConfigurationDatabase</em> or <em>Connect-SPConfigurationDatabase</em> cmdlets. The command will actually generate an error but you can safely ignore it – all we care is that it fixes the registry key for us so that we can move on to the actual provisioning.</p>

<h2>Provision-WebApplications.ps1</h2>

<p>The next script I demoed during the first session was the <strong>Provision-WebApplications.ps1</strong> script. This script, aside from the obvious of provisioning Web Applications, also provisioned any initial Site Collections and managed paths that we needed. The following illustration details the three Web Applications we created along with their Application Pool association and other relevant details:</p>

<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blog.falchionconsulting.com/wp-content/uploads/2012/05/image1.png" width="804" height="337" /></p>

<p>Now let’s take a look at the XML file that I used to provide all the configuration information:</p>

<div class="codebox">
  <pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Farm</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">WebApplications</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">WebApplication</span> <span class="attr">Name</span><span class="kwrd">=&quot;SharePoint MySites&quot;</span> <span class="attr">HostHeader</span><span class="kwrd">=&quot;my.isclondon.local&quot;</span> <span class="attr">Port</span><span class="kwrd">=&quot;80&quot;</span> <span class="attr">DefaultTimeZone</span><span class="kwrd">=&quot;2&quot;</span> <span class="attr">Path</span><span class="kwrd">=&quot;c:\sharepoint\webs\mysites&quot;</span> <span class="attr">Ssl</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">LoadBalancedUrl</span><span class="kwrd">=&quot;http://my.isclondon.local&quot;</span> <span class="attr">AllowAnonymous</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">SelfServiceSiteCreation</span><span class="kwrd">=&quot;true&quot;</span> <span class="attr">RequireContactForSsc</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">AuthenticationMode</span><span class="kwrd">=&quot;Classic&quot;</span> <span class="attr">EnableWindowsAuthentication</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">AuthenticationMethod</span><span class="kwrd">=&quot;NTLM&quot;</span> <span class="attr">EnableBasicAuthentication</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">EnableFormsBasedAuthentication</span><span class="kwrd">=&quot;false&quot;</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">ApplicationPool</span> <span class="attr">Name</span><span class="kwrd">=&quot;SharePoint Collab&quot;</span> <span class="attr">AccountName</span><span class="kwrd">=&quot;isclondon\SPCollab&quot;</span> <span class="attr">AccountPassword</span><span class="kwrd">=&quot;password&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">PortalSuperUserAccount</span> <span class="attr">AccountName</span><span class="kwrd">=&quot;isclondon\spcacheuser&quot;</span> <span class="attr">AccountPassword</span><span class="kwrd">=&quot;password&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">PortalSuperReaderAccount</span> <span class="attr">AccountName</span><span class="kwrd">=&quot;isclondon\spcachereader&quot;</span> <span class="attr">AccountPassword</span><span class="kwrd">=&quot;password&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">ManagedPaths</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">ManagedPath</span> <span class="attr">Explicit</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">RelativeURL</span><span class="kwrd">=&quot;/personal&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">ManagedPaths</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">UserPolicies</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">UserPolicy</span> <span class="attr">UserLogin</span><span class="kwrd">=&quot;isclondon\SPInstall&quot;</span> <span class="attr">UserDisplayName</span><span class="kwrd">=&quot;SharePoint Administrator&quot;</span> <span class="attr">Zone</span><span class="kwrd">=&quot;All&quot;</span><span class="kwrd">&gt;</span>
          <span class="kwrd">&lt;</span><span class="html">Permission</span> <span class="attr">Name</span><span class="kwrd">=&quot;Full Control&quot;</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">UserPolicy</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">UserPolicies</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">ProxyGroup</span> <span class="attr">Name</span><span class="kwrd">=&quot;Default&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">SPDesigner</span> <span class="attr">AllowDesigner</span><span class="kwrd">=&quot;true&quot;</span> <span class="attr">AllowRevertFromTemplate</span><span class="kwrd">=&quot;true&quot;</span> <span class="attr">AllowMasterPageEditing</span><span class="kwrd">=&quot;true&quot;</span> <span class="attr">ShowURLStructure</span><span class="kwrd">=&quot;true&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">ContentDatabases</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">ContentDatabase</span> <span class="attr">Default</span><span class="kwrd">=&quot;true&quot;</span> <span class="attr">Server</span><span class="kwrd">=&quot;ISCSharePoint1&quot;</span> <span class="attr">FailoverDatabaseServer</span><span class="kwrd">=&quot;&quot;</span> <span class="attr">Name</span><span class="kwrd">=&quot;ISC_Content_MySites&quot;</span> <span class="attr">MaxSiteCount</span><span class="kwrd">=&quot;15000&quot;</span> <span class="attr">WarningSiteCount</span><span class="kwrd">=&quot;9000&quot;</span><span class="kwrd">&gt;</span>
          <span class="kwrd">&lt;</span><span class="html">SiteCollections</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">SiteCollection</span> <span class="attr">Name</span><span class="kwrd">=&quot;My Sites&quot;</span> <span class="attr">Description</span><span class="kwrd">=&quot;My Sites Host Site Collection&quot;</span> <span class="attr">Url</span><span class="kwrd">=&quot;http://my.isclondon.local&quot;</span> <span class="attr">Template</span><span class="kwrd">=&quot;SPSMSITEHOST#0&quot;</span> <span class="attr">LCID</span><span class="kwrd">=&quot;1033&quot;</span> <span class="attr">OwnerLogin</span><span class="kwrd">=&quot;isclondon\administrator&quot;</span> <span class="attr">OwnerEmail</span><span class="kwrd">=&quot;administrator@isclondon.com&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">SiteCollection</span><span class="kwrd">&gt;</span>
          <span class="kwrd">&lt;/</span><span class="html">SiteCollections</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">ContentDatabase</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">ContentDatabases</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">WebApplication</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">WebApplication</span> <span class="attr">Name</span><span class="kwrd">=&quot;SharePoint Team Sites&quot;</span> <span class="attr">HostHeader</span><span class="kwrd">=&quot;team.isclondon.local&quot;</span> <span class="attr">Port</span><span class="kwrd">=&quot;80&quot;</span> <span class="attr">DefaultTimeZone</span><span class="kwrd">=&quot;2&quot;</span> <span class="attr">Path</span><span class="kwrd">=&quot;c:\sharepoint\webs\teams&quot;</span> <span class="attr">Ssl</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">LoadBalancedUrl</span><span class="kwrd">=&quot;http://team.isclondon.local&quot;</span> <span class="attr">AllowAnonymous</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">SelfServiceSiteCreation</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">RequireContactForSsc</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">AuthenticationMode</span><span class="kwrd">=&quot;Classic&quot;</span> <span class="attr">EnableWindowsAuthentication</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">AuthenticationMethod</span><span class="kwrd">=&quot;NTLM&quot;</span> <span class="attr">EnableBasicAuthentication</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">EnableFormsBasedAuthentication</span><span class="kwrd">=&quot;false&quot;</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">ApplicationPool</span> <span class="attr">Name</span><span class="kwrd">=&quot;SharePoint Collab&quot;</span> <span class="attr">AccountName</span><span class="kwrd">=&quot;isclondon\SPCollab&quot;</span> <span class="attr">AccountPassword</span><span class="kwrd">=&quot;password&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">PortalSuperUserAccount</span> <span class="attr">AccountName</span><span class="kwrd">=&quot;isclondon\spcacheuser&quot;</span> <span class="attr">AccountPassword</span><span class="kwrd">=&quot;password&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">PortalSuperReaderAccount</span> <span class="attr">AccountName</span><span class="kwrd">=&quot;isclondon\spcachereader&quot;</span> <span class="attr">AccountPassword</span><span class="kwrd">=&quot;password&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">ManagedPaths</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">ManagedPaths</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">UserPolicies</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">UserPolicy</span> <span class="attr">UserLogin</span><span class="kwrd">=&quot;isclondon\SPInstall&quot;</span> <span class="attr">UserDisplayName</span><span class="kwrd">=&quot;SharePoint Administrator&quot;</span> <span class="attr">Zone</span><span class="kwrd">=&quot;All&quot;</span><span class="kwrd">&gt;</span>
          <span class="kwrd">&lt;</span><span class="html">Permission</span> <span class="attr">Name</span><span class="kwrd">=&quot;Full Control&quot;</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">UserPolicy</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">UserPolicies</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">ProxyGroup</span> <span class="attr">Name</span><span class="kwrd">=&quot;Default&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">SPDesigner</span> <span class="attr">AllowDesigner</span><span class="kwrd">=&quot;true&quot;</span> <span class="attr">AllowRevertFromTemplate</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">AllowMasterPageEditing</span><span class="kwrd">=&quot;true&quot;</span> <span class="attr">ShowURLStructure</span><span class="kwrd">=&quot;true&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">ContentDatabases</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">ContentDatabase</span> <span class="attr">Default</span><span class="kwrd">=&quot;true&quot;</span> <span class="attr">Server</span><span class="kwrd">=&quot;ISCSharePoint1&quot;</span> <span class="attr">FailoverDatabaseServer</span><span class="kwrd">=&quot;&quot;</span> <span class="attr">Name</span><span class="kwrd">=&quot;ISC_Content_TeamSites&quot;</span> <span class="attr">MaxSiteCount</span><span class="kwrd">=&quot;15000&quot;</span> <span class="attr">WarningSiteCount</span><span class="kwrd">=&quot;9000&quot;</span><span class="kwrd">&gt;</span>
          <span class="kwrd">&lt;</span><span class="html">SiteCollections</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">SiteCollection</span> <span class="attr">Name</span><span class="kwrd">=&quot;Team Sites&quot;</span> <span class="attr">Url</span><span class="kwrd">=&quot;http://team.isclondon.local&quot;</span> <span class="attr">Template</span><span class="kwrd">=&quot;CMSPUBLISHING#0&quot;</span> <span class="attr">LCID</span><span class="kwrd">=&quot;1033&quot;</span> <span class="attr">OwnerLogin</span><span class="kwrd">=&quot;isclondon\administrator&quot;</span> <span class="attr">OwnerEmail</span><span class="kwrd">=&quot;administrator@isclondon.com&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">SiteCollection</span><span class="kwrd">&gt;</span>
          <span class="kwrd">&lt;/</span><span class="html">SiteCollections</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">ContentDatabase</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">ContentDatabases</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">Features</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">WebApplication</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">WebApplication</span> <span class="attr">Name</span><span class="kwrd">=&quot;SharePoint Intranet&quot;</span> <span class="attr">HostHeader</span><span class="kwrd">=&quot;intranet.isclondon.local&quot;</span> <span class="attr">Port</span><span class="kwrd">=&quot;80&quot;</span> <span class="attr">DefaultTimeZone</span><span class="kwrd">=&quot;2&quot;</span> <span class="attr">Path</span><span class="kwrd">=&quot;c:\sharepoint\webs\intranet&quot;</span> <span class="attr">Ssl</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">LoadBalancedUrl</span><span class="kwrd">=&quot;http://intranet.isclondon.local&quot;</span> <span class="attr">AllowAnonymous</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">SelfServiceSiteCreation</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">RequireContactForSsc</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">AuthenticationMode</span><span class="kwrd">=&quot;Claims&quot;</span> <span class="attr">EnableWindowsAuthentication</span><span class="kwrd">=&quot;true&quot;</span> <span class="attr">AuthenticationMethod</span><span class="kwrd">=&quot;NTLM&quot;</span> <span class="attr">EnableBasicAuthentication</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">EnableFormsBasedAuthentication</span><span class="kwrd">=&quot;false&quot;</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">ApplicationPool</span> <span class="attr">Name</span><span class="kwrd">=&quot;SharePoint Content&quot;</span> <span class="attr">AccountName</span><span class="kwrd">=&quot;isclondon\SPContent&quot;</span> <span class="attr">AccountPassword</span><span class="kwrd">=&quot;password&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">PortalSuperUserAccount</span> <span class="attr">AccountName</span><span class="kwrd">=&quot;isclondon\spcacheuser&quot;</span> <span class="attr">AccountPassword</span><span class="kwrd">=&quot;password&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">PortalSuperReaderAccount</span> <span class="attr">AccountName</span><span class="kwrd">=&quot;isclondon\spcachereader&quot;</span> <span class="attr">AccountPassword</span><span class="kwrd">=&quot;password&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">ManagedPaths</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">ManagedPath</span> <span class="attr">Explicit</span><span class="kwrd">=&quot;true&quot;</span> <span class="attr">RelativeURL</span><span class="kwrd">=&quot;/CTHub&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">ManagedPaths</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">UserPolicies</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">UserPolicy</span> <span class="attr">UserLogin</span><span class="kwrd">=&quot;isclondon\SPInstall&quot;</span> <span class="attr">UserDisplayName</span><span class="kwrd">=&quot;SharePoint Administrator&quot;</span> <span class="attr">Zone</span><span class="kwrd">=&quot;All&quot;</span><span class="kwrd">&gt;</span>
          <span class="kwrd">&lt;</span><span class="html">Permission</span> <span class="attr">Name</span><span class="kwrd">=&quot;Full Control&quot;</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">UserPolicy</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">UserPolicies</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">ProxyGroup</span> <span class="attr">Name</span><span class="kwrd">=&quot;Default&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">SPDesigner</span> <span class="attr">AllowDesigner</span><span class="kwrd">=&quot;true&quot;</span> <span class="attr">AllowRevertFromTemplate</span><span class="kwrd">=&quot;false&quot;</span> <span class="attr">AllowMasterPageEditing</span><span class="kwrd">=&quot;true&quot;</span> <span class="attr">ShowURLStructure</span><span class="kwrd">=&quot;true&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">ContentDatabases</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">ContentDatabase</span> <span class="attr">Default</span><span class="kwrd">=&quot;true&quot;</span> <span class="attr">Server</span><span class="kwrd">=&quot;ISCSharePoint1&quot;</span> <span class="attr">FailoverDatabaseServer</span><span class="kwrd">=&quot;&quot;</span> <span class="attr">Name</span><span class="kwrd">=&quot;ISC_Content_Intranet&quot;</span> <span class="attr">MaxSiteCount</span><span class="kwrd">=&quot;15000&quot;</span> <span class="attr">WarningSiteCount</span><span class="kwrd">=&quot;9000&quot;</span><span class="kwrd">&gt;</span>
          <span class="kwrd">&lt;</span><span class="html">SiteCollections</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">SiteCollection</span> <span class="attr">Name</span><span class="kwrd">=&quot;Intranet&quot;</span> <span class="attr">Url</span><span class="kwrd">=&quot;http://intranet.isclondon.local&quot;</span> <span class="attr">Template</span><span class="kwrd">=&quot;STS#0&quot;</span> <span class="attr">LCID</span><span class="kwrd">=&quot;1033&quot;</span> <span class="attr">OwnerLogin</span><span class="kwrd">=&quot;isclondon\administrator&quot;</span> <span class="attr">OwnerEmail</span><span class="kwrd">=&quot;administrator@isclondon.com&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">SiteCollection</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">SiteCollection</span> <span class="attr">Name</span><span class="kwrd">=&quot;Content Type Hub&quot;</span> <span class="attr">Url</span><span class="kwrd">=&quot;http://intranet.isclondon.local/CTHub&quot;</span> <span class="attr">Template</span><span class="kwrd">=&quot;STS#1&quot;</span> <span class="attr">LCID</span><span class="kwrd">=&quot;1033&quot;</span> <span class="attr">OwnerLogin</span><span class="kwrd">=&quot;isclondon\administrator&quot;</span> <span class="attr">OwnerEmail</span><span class="kwrd">=&quot;administrator@isclondon.com&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">SiteCollection</span><span class="kwrd">&gt;</span>
          <span class="kwrd">&lt;/</span><span class="html">SiteCollections</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">ContentDatabase</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">ContentDatabases</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">Features</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">WebApplication</span><span class="kwrd">&gt;</span>    
  <span class="kwrd">&lt;/</span><span class="html">WebApplications</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Farm</span><span class="kwrd">&gt;</span></pre>
</div>

<p>&#160;</p>

<p>At first glance the XML file, due to it’s size, may seem a bit overwhelming but hopefully as you go through it you’ll see that it really is a pretty natural and somewhat obvious structure. (Think about the possibilities if you had a great UI to manage this XML structure – wink, wink).</p>

<p>Okay, now for the code – and there’s a fair bit of it:</p>

<div class="codebox">
  <pre><span style="color: #0000ff">function</span><span style="color: #000000"> </span><span style="color: #5f9ea0">Provision-WebApplications</span><span style="color: #000000">() {
    </span><span style="color: #008000">&lt;#</span><span style="color: #008000">
    .Synopsis
        Creates the web applications.
    .Description
        Creates the web applications.
    .Example
        PS C:\&gt; . .\Provision-WebApplications.ps1
        PS C:\&gt; Provision-WebApplication -SettingsFile c:\WebApplications.xml
    .Example
        PS C:\&gt; . .\Provision-WebApplications.ps1
        PS C:\&gt; Provision-WebApplications -ConfigXml ([xml](Get-Content c:\farmconfiguration.xml))
    .Parameter SettingsFile
        The path to an XML file.
    </span><span style="color: #008000">#&gt;</span><span style="color: #000000">
    [CmdletBinding(DefaultParameterSetName</span><span style="color: #ff0000">=</span><span style="color: #800000">&quot;</span><span style="color: #800000">FilePath</span><span style="color: #800000">&quot;</span><span style="color: #000000">)]
    </span><span style="color: #0000ff">param</span><span style="color: #000000"> (
        [Parameter(Mandatory</span><span style="color: #ff0000">=</span><span style="color: #800080">$true</span><span style="color: #000000">, Position</span><span style="color: #ff0000">=</span><span style="color: #000000">0</span><span style="color: #000000">, ParameterSetName</span><span style="color: #ff0000">=</span><span style="color: #800000">&quot;</span><span style="color: #800000">XmlElement</span><span style="color: #800000">&quot;</span><span style="color: #000000">)]
        [ValidateNotNull()]
        [</span><span style="color: #008080">System.Xml.XmlElement</span><span style="color: #000000">]</span><span style="color: #800080">$ConfigElement</span><span style="color: #000000">,

        [Parameter(Mandatory</span><span style="color: #ff0000">=</span><span style="color: #800080">$true</span><span style="color: #000000">, Position</span><span style="color: #ff0000">=</span><span style="color: #000000">0</span><span style="color: #000000">, ParameterSetName</span><span style="color: #ff0000">=</span><span style="color: #800000">&quot;</span><span style="color: #800000">XmlDocument</span><span style="color: #800000">&quot;</span><span style="color: #000000">)]
        [ValidateNotNull()]
        [</span><span style="color: #008080">xml</span><span style="color: #000000">]</span><span style="color: #800080">$ConfigXml</span><span style="color: #000000">,

        [Parameter(Mandatory</span><span style="color: #ff0000">=</span><span style="color: #800080">$true</span><span style="color: #000000">, Position</span><span style="color: #ff0000">=</span><span style="color: #000000">0</span><span style="color: #000000">, ParameterSetName</span><span style="color: #ff0000">=</span><span style="color: #800000">&quot;</span><span style="color: #800000">FilePath</span><span style="color: #800000">&quot;</span><span style="color: #000000">)]
        [ValidateNotNullOrEmpty()]
        [</span><span style="color: #008080">string</span><span style="color: #000000">]</span><span style="color: #800080">$SettingsFile</span><span style="color: #000000">
    )
    </span><span style="color: #0000ff">switch</span><span style="color: #000000"> (</span><span style="color: #800080">$PsCmdlet</span><span style="color: #000000">.ParameterSetName) { 
        </span><span style="color: #800000">&quot;</span><span style="color: #800000">XmlDocument</span><span style="color: #800000">&quot;</span><span style="color: #000000"> { 
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$ConfigXml</span><span style="color: #000000">.Farm.WebApplications.WebApplication </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
                </span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (</span><span style="color: #800080">$appConfig</span><span style="color: #000000"> </span><span style="color: #0000ff">in</span><span style="color: #000000"> </span><span style="color: #800080">$ConfigXml</span><span style="color: #000000">.Farm.WebApplications.WebApplication) {
                    </span><span style="color: #5f9ea0">Provision-WebApplications</span><span style="color: #000000"> -ConfigElement </span><span style="color: #800080">$appConfig</span><span style="color: #000000">
                }
                </span><span style="color: #0000ff">return</span><span style="color: #000000">
            }
        }
        </span><span style="color: #800000">&quot;</span><span style="color: #800000">FilePath</span><span style="color: #800000">&quot;</span><span style="color: #000000"> {
            </span><span style="color: #5f9ea0">Provision-WebApplications</span><span style="color: #000000"> -ConfigXml ([</span><span style="color: #008080">xml</span><span style="color: #000000">](</span><span style="color: #5f9ea0; font-weight: bold">Get-Content</span><span style="color: #000000"> </span><span style="color: #800080">$SettingsFile</span><span style="color: #000000">))
            </span><span style="color: #0000ff">return</span><span style="color: #000000">
        }
    }
    </span><span style="color: #800080">$config</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$ConfigElement</span><span style="color: #000000">

    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$config</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Warning</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">No web application defined. Skipping.</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #0000ff">return</span><span style="color: #000000">
    }

    
    </span><span style="color: #800080">$webApp</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPWebApplication</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Identity</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Name </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000">
    
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$webApp</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
        </span><span style="color: #800080">$allowAnon</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> [</span><span style="color: #008080">bool</span><span style="color: #000000">]::</span><span style="color: #8b4513">Parse</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.AllowAnonymous.ToString())
        </span><span style="color: #800080">$ssl</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> [</span><span style="color: #008080">bool</span><span style="color: #000000">]::</span><span style="color: #8b4513">Parse</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.Ssl.ToString())

        </span><span style="color: #800080">$db</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$config</span><span style="color: #000000">.ContentDatabases </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
            </span><span style="color: #0000ff">throw</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">A content database configuration setting could not be found for `&quot;$($config.Name)`&quot;.</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        }
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$config</span><span style="color: #000000">.ContentDatabases.ChildNodes.Count </span><span style="color: #ff0000">-gt</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">) {
            </span><span style="color: #800080">$db</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.ContentDatabases.ContentDatabase | </span><span style="color: #5f9ea0; font-weight: bold">where</span><span style="color: #000000"> {</span><span style="color: #800080">$_</span><span style="color: #000000">.Default </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">true</span><span style="color: #800000">&quot;</span><span style="color: #000000">}
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$db</span><span style="color: #000000"> </span><span style="color: #ff0000">-is</span><span style="color: #000000"> [</span><span style="color: #008080">array</span><span style="color: #000000">]) {
                </span><span style="color: #5f9ea0; font-weight: bold">Write-Warning</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Multiple content databases set as default for `&quot;$($config.Name)`&quot; (using first)</span><span style="color: #800000">&quot;</span><span style="color: #000000">
                </span><span style="color: #800080">$db</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$db</span><span style="color: #000000">[0]
            }
        } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
            </span><span style="color: #800080">$db</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.ContentDatabases.ContentDatabase
        }
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$db</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
            </span><span style="color: #0000ff">throw</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">A content database configuration setting could not be found for `&quot;$($config.Name)`&quot;.</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        }
        
        </span><span style="color: #800080">$poolName</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.ApplicationPool.Name
        </span><span style="color: #800080">$poolAcctName</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.ApplicationPool.AccountName
        </span><span style="color: #800080">$poolAcctPwd</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.ApplicationPool.AccountPassword
        </span><span style="color: #800080">$poolAcct</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">
        
        </span><span style="color: #008000">#</span><span style="color: #008000">Check for existing Application Pool</span><span style="color: #008000">
</span><span style="color: #000000">        </span><span style="color: #800080">$pools</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> [</span><span style="color: #008080">Microsoft.SharePoint.Administration.SPWebService</span><span style="color: #000000">]::</span><span style="color: #8b4513">ContentService</span><span style="color: #000000">.</span><span style="color: #8b4513">ApplicationPools</span><span style="color: #000000">
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> ((</span><span style="color: #800080">$pools</span><span style="color: #000000"> | ? {</span><span style="color: #800080">$_</span><span style="color: #000000">.Name </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$poolName</span><span style="color: #000000">}) </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
            </span><span style="color: #800080">$poolAcct</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPManagedAccount</span><span style="color: #000000"> </span><span style="color: #800080">$poolAcctName</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000">
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$poolAcct</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
                </span><span style="color: #800080">$securePwd</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">ConvertTo-SecureString</span><span style="color: #000000"> </span><span style="color: #800080">$poolAcctPwd</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-AsPlainText</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-force</span><span style="color: #000000">
                </span><span style="color: #800080">$cred</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-Object</span><span style="color: #000000"> </span><span style="color: #800000">System.Management.Automation.PSCredential</span><span style="color: #000000"> </span><span style="color: #800080">$poolAcctName</span><span style="color: #000000">, </span><span style="color: #800080">$securePwd</span><span style="color: #000000">
                </span><span style="color: #800080">$poolAcct</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-SPManagedAccount</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Credential</span><span style="color: #000000"> </span><span style="color: #800080">$cred</span><span style="color: #000000">
            }
        }
        
        </span><span style="color: #800080">$loadBalancedUrl</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.LoadBalancedUrl
        </span><span style="color: #800080">$port</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Port
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$loadBalancedUrl</span><span style="color: #000000">)) {
            </span><span style="color: #800080">$loadBalancedUri</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-Object</span><span style="color: #000000"> </span><span style="color: #800000">System.Uri</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.LoadBalancedUrl
            </span><span style="color: #800080">$port</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$loadBalancedUri</span><span style="color: #000000">.Port
            </span><span style="color: #800080">$loadBalancedUrl</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">$($loadBalancedUri.Scheme)://$($loadBalancedUri.Host)/</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.HostHeader)) {
                </span><span style="color: #800080">$loadBalancedUrl</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">http://$($config.HostHeader)</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            }
        }
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> ([</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$port</span><span style="color: #000000">)) { </span><span style="color: #800080">$port</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">80</span><span style="color: #800000">&quot;</span><span style="color: #000000"> }

        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$config</span><span style="color: #000000">.AuthenticationMode </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Claims</span><span style="color: #800000">&quot;</span><span style="color: #000000">) {
            </span><span style="color: #800080">$authProviders</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> @()
            </span><span style="color: #800080">$enableWindowsAuthentication</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$false</span><span style="color: #000000">
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.EnableWindowsAuthentication)) { </span><span style="color: #800080">$enableWindowsAuthentication</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> [</span><span style="color: #008080">bool</span><span style="color: #000000">]::</span><span style="color: #8b4513">Parse</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.EnableWindowsAuthentication) }
            </span><span style="color: #800080">$enableFormsBasedAuthentication</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$false</span><span style="color: #000000">
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.EnableFormsBasedAuthentication)) { </span><span style="color: #800080">$enableFormsBasedAuthentication</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> [</span><span style="color: #008080">bool</span><span style="color: #000000">]::</span><span style="color: #8b4513">Parse</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.EnableFormsBasedAuthentication) }

            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$enableWindowsAuthentication</span><span style="color: #000000">) {
                </span><span style="color: #800080">$enableBasicAuthentication</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$false</span><span style="color: #000000">
                </span><span style="color: #0000ff">if</span><span style="color: #000000"> (![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.EnableBasicAuthentication)) { </span><span style="color: #800080">$enableBasicAuthentication</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> [</span><span style="color: #008080">bool</span><span style="color: #000000">]::</span><span style="color: #8b4513">Parse</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.EnableBasicAuthentication) }
                </span><span style="color: #800080">$disableKerberos</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.AuthenticationMethod </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">NTLM</span><span style="color: #800000">&quot;</span><span style="color: #000000">
                </span><span style="color: #800080">$authProviders</span><span style="color: #000000"> </span><span style="color: #ff0000">+=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-SPAuthenticationProvider</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                    </span><span style="font-style: italic; color: #5f9ea0">-UseWindowsIntegratedAuthentication</span><span style="color: #000000">:</span><span style="color: #800080">$enableWindowsAuthentication</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                    </span><span style="font-style: italic; color: #5f9ea0">-DisableKerberos</span><span style="color: #000000">:</span><span style="color: #800080">$disableKerberos</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                    </span><span style="font-style: italic; color: #5f9ea0">-UseBasicAuthentication</span><span style="color: #000000">:</span><span style="color: #800080">$enableBasicAuthentication</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                    </span><span style="font-style: italic; color: #5f9ea0">-AllowAnonymous</span><span style="color: #000000">:</span><span style="color: #800080">$allowAnon</span><span style="color: #000000">
            }
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$enableFormsBasedAuthentication</span><span style="color: #000000">) {
                </span><span style="color: #800080">$authProviders</span><span style="color: #000000"> </span><span style="color: #ff0000">+=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-SPAuthenticationProvider</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                    </span><span style="font-style: italic; color: #5f9ea0">-ASPNETMembershipProvider</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.ASPNETMembershipProviderName </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                    </span><span style="font-style: italic; color: #5f9ea0">-ASPNETRoleProviderName</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.ASPNETRoleManagerName 
            }
            </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Creating Web Application: `&quot;$($config.Name)`&quot;</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            </span><span style="color: #800080">$webApp</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-SPWebApplication</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-SecureSocketsLayer</span><span style="color: #000000">:</span><span style="color: #800080">$ssl</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-AllowAnonymousAccess</span><span style="color: #000000">:</span><span style="color: #800080">$allowAnon</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-ApplicationPool</span><span style="color: #000000"> </span><span style="color: #800080">$poolName</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-ApplicationPoolAccount</span><span style="color: #000000"> </span><span style="color: #800080">$poolAcct</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-Name</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Name </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-AuthenticationProvider</span><span style="color: #000000"> </span><span style="color: #800080">$authProviders</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-DatabaseServer</span><span style="color: #000000"> </span><span style="color: #800080">$db</span><span style="color: #000000">.Server </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-DatabaseName</span><span style="color: #000000"> </span><span style="color: #800080">$db</span><span style="color: #000000">.Name </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-HostHeader</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.HostHeader </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-Path</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Path </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-Port</span><span style="color: #000000"> </span><span style="color: #800080">$port</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-Url</span><span style="color: #000000"> </span><span style="color: #800080">$loadBalancedUrl</span><span style="color: #000000">
        } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
            </span><span style="color: #800080">$authMethod</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">NTLM</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.AuthenticationMethod)) { </span><span style="color: #800080">$authMethod</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.AuthenticationMethod }

            </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Creating Web Application: `&quot;$($config.Name)`&quot;</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            </span><span style="color: #800080">$webApp</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-SPWebApplication</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-SecureSocketsLayer</span><span style="color: #000000">:</span><span style="color: #800080">$ssl</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-AllowAnonymousAccess</span><span style="color: #000000">:</span><span style="color: #800080">$allowAnon</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-ApplicationPool</span><span style="color: #000000"> </span><span style="color: #800080">$poolName</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-ApplicationPoolAccount</span><span style="color: #000000"> </span><span style="color: #800080">$poolAcct</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-Name</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Name </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-AuthenticationMethod</span><span style="color: #000000"> </span><span style="color: #800080">$authMethod</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-DatabaseServer</span><span style="color: #000000"> </span><span style="color: #800080">$db</span><span style="color: #000000">.Server </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-DatabaseName</span><span style="color: #000000"> </span><span style="color: #800080">$db</span><span style="color: #000000">.Name </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-HostHeader</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.HostHeader </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-Path</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Path </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-Port</span><span style="color: #000000"> </span><span style="color: #800080">$port</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-Url</span><span style="color: #000000"> </span><span style="color: #800080">$loadBalancedUrl</span><span style="color: #000000">
        }

        </span><span style="color: #5f9ea0; font-weight: bold">Set-SPWebApplication</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Identity</span><span style="color: #000000"> </span><span style="color: #800080">$webApp</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-DefaultTimeZone</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.DefaultTimeZone

        </span><span style="color: #008000">#</span><span style="color: #008000">Re-get the web app to avoid update conflicts</span><span style="color: #008000">
</span><span style="color: #000000">        </span><span style="color: #800080">$webApp</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPWebApplication</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Identity</span><span style="color: #000000">  </span><span style="color: #800080">$webApp</span><span style="color: #000000">
        </span><span style="color: #800080">$webApp</span><span style="color: #000000">.SelfServiceSiteCreationEnabled </span><span style="color: #ff0000">=</span><span style="color: #000000"> [</span><span style="color: #008080">bool</span><span style="color: #000000">]::</span><span style="color: #8b4513">Parse</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.SelfServiceSiteCreation)
        </span><span style="color: #800080">$webApp</span><span style="color: #000000">.RequireContactForSelfServiceSiteCreation </span><span style="color: #ff0000">=</span><span style="color: #000000"> [</span><span style="color: #008080">bool</span><span style="color: #000000">]::</span><span style="color: #8b4513">Parse</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.RequireContactForSsc)
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$config</span><span style="color: #000000">.ProxyGroup </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000"> </span><span style="color: #ff0000">-and</span><span style="color: #000000"> ![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.ProxyGroup.Name)) {
            </span><span style="color: #800080">$proxyGroupName</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.ProxyGroup.Name
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$proxyGroupName</span><span style="color: #000000"> </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
                </span><span style="color: #800080">$webApp</span><span style="color: #000000">.ServiceApplicationProxyGroup </span><span style="color: #ff0000">=</span><span style="color: #000000"> Get-ProxyGroup </span><span style="color: #800080">$proxyGroupName</span><span style="color: #000000"> </span><span style="color: #800080">$true</span><span style="color: #000000">
            }
        }
        </span><span style="color: #800080">$webApp</span><span style="color: #000000">.Update()
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;&quot;&quot;</span><span style="color: #800000">$($config.Name)</span><span style="color: #800000">&quot;&quot;</span><span style="color: #800000"> successfully created.</span><span style="color: #800000">&quot;</span><span style="color: #000000">
    } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
        </span><span style="color: #008000">#</span><span style="color: #008000">We got the web app so return it and don't attempt to recreate</span><span style="color: #008000">
</span><span style="color: #000000">        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;&quot;&quot;</span><span style="color: #800000">$($config.Name)</span><span style="color: #800000">&quot;&quot;</span><span style="color: #800000"> already exists, skipping creation.</span><span style="color: #800000">&quot;</span><span style="color: #000000">
    }
    </span><span style="color: #800080">$setObjectCacheAccounts</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$true</span><span style="color: #000000">
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.PortalSuperUserAccount) </span><span style="color: #ff0000">-and</span><span style="color: #000000"> ![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.PortalSuperReaderAccount)) {
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$config</span><span style="color: #000000">.PortalSuperUserAccount.AccountName </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.PortalSuperReaderAccount.AccountName) {
            </span><span style="color: #5f9ea0; font-weight: bold">Write-Warning</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">The Portal Super User Account and Portal Super Reader Account must not be the same account as this will result in a security hole. The accounts will not be set.</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            </span><span style="color: #800080">$setObjectCacheAccounts</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$false</span><span style="color: #000000">
        }
    }
    </span><span style="color: #800080">$claimsPrefix</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;&quot;</span><span style="color: #000000">
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$config</span><span style="color: #000000">.AuthenticationMode </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Claims</span><span style="color: #800000">&quot;</span><span style="color: #000000">) {
        </span><span style="color: #800080">$claimsPrefix</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">i:0#.w|</span><span style="color: #800000">&quot;</span><span style="color: #000000">
    }
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.PortalSuperUserAccount.AccountName) </span><span style="color: #ff0000">-and</span><span style="color: #000000"> </span><span style="color: #800080">$setObjectCacheAccounts</span><span style="color: #000000">) {
        </span><span style="color: #800080">$webApp</span><span style="color: #000000">.Properties[</span><span style="color: #800000">&quot;</span><span style="color: #800000">portalsuperuseraccount</span><span style="color: #800000">&quot;</span><span style="color: #000000">] </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">$claimsPrefix$($config.PortalSuperUserAccount.AccountName)</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        Set-WebAppUserPolicy </span><span style="color: #800080">$webApp</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">$claimsPrefix$($config.PortalSuperUserAccount.AccountName)</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.PortalSuperUserAccount.AccountName </span><span style="color: #800000">&quot;</span><span style="color: #800000">Full Control</span><span style="color: #800000">&quot;</span><span style="color: #000000">
    }
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.PortalSuperReaderAccount.AccountName) </span><span style="color: #ff0000">-and</span><span style="color: #000000"> </span><span style="color: #800080">$setObjectCacheAccounts</span><span style="color: #000000">) {
        </span><span style="color: #800080">$webApp</span><span style="color: #000000">.Properties[</span><span style="color: #800000">&quot;</span><span style="color: #800000">portalsuperreaderaccount</span><span style="color: #800000">&quot;</span><span style="color: #000000">] </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">$claimsPrefix$($config.PortalSuperReaderAccount.AccountName)</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        Set-WebAppUserPolicy </span><span style="color: #800080">$webApp</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">$claimsPrefix$($config.PortalSuperReaderAccount.AccountName)</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.PortalSuperReaderAccount.AccountName </span><span style="color: #800000">&quot;</span><span style="color: #800000">Full Read</span><span style="color: #800000">&quot;</span><span style="color: #000000">
    }


    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$config</span><span style="color: #000000">.UserPolicies) {
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Creating user policies...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        [</span><span style="color: #008080">bool</span><span style="color: #000000">]</span><span style="color: #800080">$updateRequired</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$false</span><span style="color: #000000">
        </span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (</span><span style="color: #800080">$userPolicyConfig</span><span style="color: #000000"> </span><span style="color: #0000ff">in</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.UserPolicies.UserPolicy) {
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$userPolicyConfig</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) { </span><span style="color: #0000ff">continue</span><span style="color: #000000"> }

            [</span><span style="color: #008080">string</span><span style="color: #000000">]</span><span style="color: #800080">$zoneName</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$userPolicyConfig</span><span style="color: #000000">.Zone
            [</span><span style="color: #008080">Microsoft.SharePoint.Administration.SPPolicyCollection</span><span style="color: #000000">]</span><span style="color: #800080">$policies</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$webApp</span><span style="color: #000000">.Policies
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$zoneName</span><span style="color: #000000">.ToLower() </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">all</span><span style="color: #800000">&quot;</span><span style="color: #000000">) {
                </span><span style="color: #800080">$policies</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$webApp</span><span style="color: #000000">.ZonePolicies(</span><span style="color: #800080">$zoneName</span><span style="color: #000000">)
            }
            </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Adding user policy for: $claimsPrefix$($userPolicyConfig.UserLogin)...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            [</span><span style="color: #008080">Microsoft.SharePoint.Administration.SPPolicy</span><span style="color: #000000">]</span><span style="color: #800080">$policy</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$policies</span><span style="color: #000000">.Add(</span><span style="color: #800000">&quot;</span><span style="color: #800000">$claimsPrefix$($userPolicyConfig.UserLogin)</span><span style="color: #800000">&quot;</span><span style="color: #000000">, </span><span style="color: #800080">$userPolicyConfig</span><span style="color: #000000">.UserDisplayName)
            </span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (</span><span style="color: #800080">$permConfig</span><span style="color: #000000"> </span><span style="color: #0000ff">in</span><span style="color: #000000"> </span><span style="color: #800080">$userPolicyConfig</span><span style="color: #000000">.Permission) {
                [</span><span style="color: #008080">Microsoft.SharePoint.Administration.SPPolicyRole</span><span style="color: #000000">]</span><span style="color: #800080">$policyRole</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$webApp</span><span style="color: #000000">.PolicyRoles | </span><span style="color: #5f9ea0; font-weight: bold">where</span><span style="color: #000000"> {</span><span style="color: #800080">$_</span><span style="color: #000000">.Name </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$permConfig</span><span style="color: #000000">.Name}
                </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$policyRole</span><span style="color: #000000"> </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
                    </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Adding policy role: $($permConfig.Name)...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
                    </span><span style="color: #800080">$policy</span><span style="color: #000000">.PolicyRoleBindings.Add(</span><span style="color: #800080">$policyRole</span><span style="color: #000000">)
                }
            }
            </span><span style="color: #800080">$updateRequired</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$true</span><span style="color: #000000">
        }
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$updateRequired</span><span style="color: #000000">) {
            </span><span style="color: #800080">$webApp</span><span style="color: #000000">.Update()
        }
    }
    
    
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$config</span><span style="color: #000000">.ManagedPaths) {
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Creating managed paths...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (</span><span style="color: #800080">$mpConfig</span><span style="color: #000000"> </span><span style="color: #0000ff">in</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.ManagedPaths.ManagedPath) {
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$mpConfig</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) { </span><span style="color: #0000ff">continue</span><span style="color: #000000"> }

            </span><span style="color: #800080">$path</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPManagedPath</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Identity</span><span style="color: #000000"> </span><span style="color: #800080">$mpConfig</span><span style="color: #000000">.RelativeURL </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-WebApplication</span><span style="color: #000000"> </span><span style="color: #800080">$webApp</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000">
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$path</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
                </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Creating </span><span style="color: #800000">&quot;&quot;</span><span style="color: #800000">$($mpConfig.RelativeURL)</span><span style="color: #800000">&quot;&quot;</span><span style="color: #800000">...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
                </span><span style="color: #5f9ea0; font-weight: bold">New-SPManagedPath</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-RelativeURL</span><span style="color: #000000"> </span><span style="color: #800080">$mpConfig</span><span style="color: #000000">.RelativeURL </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                    </span><span style="font-style: italic; color: #5f9ea0">-Explicit</span><span style="color: #000000"> <img src='http://blog.falchionconsulting.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> [</span><span style="color: #008080">bool</span><span style="color: #000000">]::</span><span style="color: #8b4513">Parse</span><span style="color: #000000">(</span><span style="color: #800080">$mpConfig</span><span style="color: #000000">.Explicit)) -WebApplication </span><span style="color: #800080">$webApp</span><span style="color: #000000">
            } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
                </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Managed path already exists: </span><span style="color: #800000">&quot;&quot;</span><span style="color: #800000">$($mpConfig.RelativeURL)</span><span style="color: #800000">&quot;&quot;</span><span style="color: #800000">.</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            }
        }
    }
    
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$config</span><span style="color: #000000">.SPDesigner) {
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Configuring SharePoint Designer Settings...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #5f9ea0; font-weight: bold">sleep</span><span style="color: #000000"> </span><span style="color: #000000">5</span><span style="color: #000000">
        </span><span style="color: #008000">#</span><span style="color: #008000">Get the web app again to avoid an update conflict</span><span style="color: #008000">
</span><span style="color: #000000">        </span><span style="color: #800080">$webApp</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPWebApplication</span><span style="color: #000000"> </span><span style="color: #800080">$webApp</span><span style="color: #000000">
        </span><span style="color: #800080">$webApp</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">Set-SPDesignerSettings</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
            </span><span style="font-style: italic; color: #5f9ea0">-AllowDesigner</span><span style="color: #000000"> ([</span><span style="color: #008080">bool</span><span style="color: #000000">]::</span><span style="color: #8b4513">Parse</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.SPDesigner.AllowDesigner)) </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
            -AllowRevertFromTemplate ([</span><span style="color: #008080">bool</span><span style="color: #000000">]::</span><span style="color: #8b4513">Parse</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.SPDesigner.AllowRevertFromTemplate)) </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
            -AllowMasterPageEditing ([</span><span style="color: #008080">bool</span><span style="color: #000000">]::</span><span style="color: #8b4513">Parse</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.SPDesigner.AllowMasterPageEditing)) </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
            -ShowURLStructure ([</span><span style="color: #008080">bool</span><span style="color: #000000">]::</span><span style="color: #8b4513">Parse</span><span style="color: #000000">(</span><span style="color: #800080">$config</span><span style="color: #000000">.SPDesigner.ShowURLStructure))
        </span><span style="color: #800080">$webApp</span><span style="color: #000000">.Update()
    }

    </span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (</span><span style="color: #800080">$dbConfig</span><span style="color: #000000"> </span><span style="color: #0000ff">in</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.ContentDatabases.ContentDatabase) {
        </span><span style="color: #800080">$db</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPContentDatabase</span><span style="color: #000000"> </span><span style="color: #800080">$dbConfig</span><span style="color: #000000">.Name </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000">
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$db</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) { 
            </span><span style="color: #800080">$db</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-SPContentDatabase</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Name</span><span style="color: #000000"> </span><span style="color: #800080">$dbConfig</span><span style="color: #000000">.Name </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-WebApplication</span><span style="color: #000000"> </span><span style="color: #800080">$webApp</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-DatabaseServer</span><span style="color: #000000"> </span><span style="color: #800080">$dbConfig</span><span style="color: #000000">.Server </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-MaxSiteCount</span><span style="color: #000000"> </span><span style="color: #800080">$dbConfig</span><span style="color: #000000">.MaxSiteCount </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-WarningSiteCount</span><span style="color: #000000"> </span><span style="color: #800080">$dbConfig</span><span style="color: #000000">.WarningSiteCount
        }
        </span><span style="color: #800080">$failoverDbServer</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$dbConfig</span><span style="color: #000000">.FailoverDatabaseServer
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$failoverDbServer</span><span style="color: #000000">)) {
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> ((</span><span style="color: #800080">$db</span><span style="color: #000000">.FailoverServiceInstance </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) </span><span style="color: #ff0000">-or</span><span style="color: #000000"> ![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">Equals</span><span style="color: #000000">(</span><span style="color: #800080">$db</span><span style="color: #000000">.FailoverServiceInstance.NormalizedDataSource, </span><span style="color: #800080">$failoverDbServer</span><span style="color: #000000">, [</span><span style="color: #008080">StringComparison</span><span style="color: #000000">]::</span><span style="color: #8b4513">OrdinalIgnoreCase</span><span style="color: #000000">)) {
                </span><span style="color: #0000ff">try</span><span style="color: #000000"> {
                    </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Adding failover database instance...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
                    </span><span style="color: #800080">$db</span><span style="color: #000000">.AddFailoverServiceInstance(</span><span style="color: #800080">$failoverDbServer</span><span style="color: #000000">)
                    </span><span style="color: #800080">$db</span><span style="color: #000000">.Update()
                } </span><span style="color: #0000ff">catch</span><span style="color: #000000"> {
                    </span><span style="color: #5f9ea0; font-weight: bold">Write-Warning</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Unable to set failover database server. $_</span><span style="color: #800000">&quot;</span><span style="color: #000000">
                }
            }
        }
        </span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (</span><span style="color: #800080">$siteConfig</span><span style="color: #000000"> </span><span style="color: #0000ff">in</span><span style="color: #000000"> </span><span style="color: #800080">$dbConfig</span><span style="color: #000000">.SiteCollections.SiteCollection) {
            </span><span style="color: #800080">$site</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPSite</span><span style="color: #000000"> </span><span style="color: #800080">$siteConfig</span><span style="color: #000000">.Url </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000">
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$site</span><span style="color: #000000"> </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
                </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Site Collection $($siteConfig.Url) already exists. Skipping.</span><span style="color: #800000">&quot;</span><span style="color: #000000">
                </span><span style="color: #800080">$site</span><span style="color: #000000">.Dispose()
                </span><span style="color: #0000ff">continue</span><span style="color: #000000">
            }
            
            </span><span style="color: #800080">$lcid</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$siteConfig</span><span style="color: #000000">.LCID
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> ([</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$lcid</span><span style="color: #000000">)) { </span><span style="color: #800080">$lcid</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> [</span><span style="color: #008080">Microsoft.SharePoint.SPRegionalSettings</span><span style="color: #000000">]::</span><span style="color: #8b4513">GlobalServerLanguage</span><span style="color: #000000">.</span><span style="color: #8b4513">LCID</span><span style="color: #000000"> }

            </span><span style="color: #800080">$optionalParams</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> @{}
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$siteConfig</span><span style="color: #000000">.SecondaryLogin)) { 
                </span><span style="color: #800080">$optionalParams</span><span style="color: #000000"> </span><span style="color: #ff0000">+=</span><span style="color: #000000"> @{</span><span style="color: #800000">&quot;</span><span style="color: #800000">SecondaryOwnerAlias</span><span style="color: #800000">&quot;</span><span style="color: #ff0000">=</span><span style="color: #800080">$siteConfig</span><span style="color: #000000">.SecondaryLogin} }
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$siteConfig</span><span style="color: #000000">.SecondaryEmail)) { 
                </span><span style="color: #800080">$optionalParams</span><span style="color: #000000"> </span><span style="color: #ff0000">+=</span><span style="color: #000000"> @{</span><span style="color: #800000">&quot;</span><span style="color: #800000">SecondaryEmail</span><span style="color: #800000">&quot;</span><span style="color: #ff0000">=</span><span style="color: #800080">$siteConfig</span><span style="color: #000000">.SecondaryEmail} }
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$siteConfig</span><span style="color: #000000">.OwnerEmail)) { 
                </span><span style="color: #800080">$optionalParams</span><span style="color: #000000"> </span><span style="color: #ff0000">+=</span><span style="color: #000000"> @{</span><span style="color: #800000">&quot;</span><span style="color: #800000">OwnerEmail</span><span style="color: #800000">&quot;</span><span style="color: #ff0000">=</span><span style="color: #800080">$siteConfig</span><span style="color: #000000">.OwnerEmail} }

            </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Creating Site Collection $($siteConfig.Url)...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            </span><span style="color: #800080">$site</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-SPSite</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-Url</span><span style="color: #000000"> </span><span style="color: #800080">$siteConfig</span><span style="color: #000000">.Url </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-Description</span><span style="color: #000000"> </span><span style="color: #800080">$siteConfig</span><span style="color: #000000">.Description </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-Language</span><span style="color: #000000"> </span><span style="color: #800080">$lcid</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-Name</span><span style="color: #000000"> </span><span style="color: #800080">$siteConfig</span><span style="color: #000000">.Name </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-OwnerAlias</span><span style="color: #000000"> </span><span style="color: #800080">$siteConfig</span><span style="color: #000000">.OwnerLogin </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-Template</span><span style="color: #000000"> </span><span style="color: #800080">$siteConfig</span><span style="color: #000000">.Template </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-ContentDatabase</span><span style="color: #000000"> </span><span style="color: #800080">$db</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #0000ff">Continue</span><span style="color: #000000"> @optionalParams

            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$site</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) { 
                </span><span style="color: #5f9ea0; font-weight: bold">Write-Warning</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Site collection was not created!</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
                </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Site collection successfully created: $($siteConfig.Url)</span><span style="color: #800000">&quot;</span><span style="color: #000000">
                </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Setting default associated security groups...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
                </span><span style="color: #5f9ea0; font-weight: bold">sleep</span><span style="color: #000000"> </span><span style="color: #000000">5</span><span style="color: #000000">
                </span><span style="color: #800080">$refreshedSite</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$site</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">Get-SPSite</span><span style="color: #000000">
                </span><span style="color: #800080">$secondaryLogin</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$siteConfig</span><span style="color: #000000">.SecondaryLogin
                </span><span style="color: #0000ff">if</span><span style="color: #000000"> (![</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$secondaryLogin</span><span style="color: #000000">)) { </span><span style="color: #800080">$secondaryLogin</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">$claimsPrefix$secondaryLogin</span><span style="color: #800000">&quot;</span><span style="color: #000000"> }
                </span><span style="color: #800080">$refreshedSite</span><span style="color: #000000">.RootWeb.CreateDefaultAssociatedGroups(</span><span style="color: #800000">&quot;</span><span style="color: #800000">$claimsPrefix$($siteConfig.OwnerLogin)</span><span style="color: #800000">&quot;</span><span style="color: #000000">, </span><span style="color: #800080">$secondaryLogin</span><span style="color: #000000">, </span><span style="color: #800080">$siteConfig</span><span style="color: #000000">.Name)
                </span><span style="color: #800080">$refreshedSite</span><span style="color: #000000">.Dispose()
                </span><span style="color: #800080">$site</span><span style="color: #000000">.Dispose()
            }
        }
    }
}

</span><span style="color: #0000ff">function</span><span style="color: #000000"> </span><span style="color: #5f9ea0">Get-ProxyGroup</span><span style="color: #000000">([</span><span style="color: #008080">string</span><span style="color: #000000">]</span><span style="color: #800080">$name</span><span style="color: #000000">, [</span><span style="color: #008080">bool</span><span style="color: #000000">]</span><span style="color: #800080">$createIfMissing</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$true</span><span style="color: #000000">) {
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$name</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Default</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="color: #ff0000">-or</span><span style="color: #000000"> [</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$name</span><span style="color: #000000">)) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> [</span><span style="color: #008080">Microsoft.SharePoint.Administration.SPServiceApplicationProxyGroup</span><span style="color: #000000">]::</span><span style="color: #8b4513">Default</span><span style="color: #000000"> }
    
    </span><span style="color: #800080">$proxyGroup</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPServiceApplicationProxyGroup</span><span style="color: #000000"> </span><span style="color: #800080">$name</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ErrorVariable</span><span style="color: #000000"> </span><span style="color: #800000">err</span><span style="color: #000000">
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$err</span><span style="color: #000000"> </span><span style="color: #ff0000">-and</span><span style="color: #000000"> </span><span style="color: #ff0000">!</span><span style="color: #800080">$createIfMissing</span><span style="color: #000000">) { </span><span style="color: #0000ff">throw</span><span style="color: #000000"> </span><span style="color: #800080">$err</span><span style="color: #000000"> }
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$proxyGroup</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
        </span><span style="color: #800080">$proxyGroup</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-SPServiceApplicationProxyGroup</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Name</span><span style="color: #000000"> </span><span style="color: #800080">$name</span><span style="color: #000000">
    }
    </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #800080">$proxyGroup</span><span style="color: #000000">
}

</span><span style="color: #0000ff">function</span><span style="color: #000000"> </span><span style="color: #5f9ea0">Set-WebAppUserPolicy</span><span style="color: #000000">(</span><span style="color: #800080">$webApp</span><span style="color: #000000">, </span><span style="color: #800080">$userName</span><span style="color: #000000">, </span><span style="color: #800080">$userDisplayName</span><span style="color: #000000">, </span><span style="color: #800080">$perm</span><span style="color: #000000">) {
    [</span><span style="color: #008080">Microsoft.SharePoint.Administration.SPPolicyCollection</span><span style="color: #000000">]</span><span style="color: #800080">$policies</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$webApp</span><span style="color: #000000">.Policies
    [</span><span style="color: #008080">Microsoft.SharePoint.Administration.SPPolicy</span><span style="color: #000000">]</span><span style="color: #800080">$policy</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$policies</span><span style="color: #000000">.Add(</span><span style="color: #800080">$userName</span><span style="color: #000000">, </span><span style="color: #800080">$userDisplayName</span><span style="color: #000000">)
    [</span><span style="color: #008080">Microsoft.SharePoint.Administration.SPPolicyRole</span><span style="color: #000000">]</span><span style="color: #800080">$policyRole</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$webApp</span><span style="color: #000000">.PolicyRoles | </span><span style="color: #5f9ea0; font-weight: bold">where</span><span style="color: #000000"> {</span><span style="color: #800080">$_</span><span style="color: #000000">.Name </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$perm</span><span style="color: #000000">}
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$policyRole</span><span style="color: #000000"> </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
        </span><span style="color: #800080">$policy</span><span style="color: #000000">.PolicyRoleBindings.Add(</span><span style="color: #800080">$policyRole</span><span style="color: #000000">)
    }
    </span><span style="color: #800080">$webApp</span><span style="color: #000000">.Update()
}
</span></pre>
</div>

<p>&#160;</p>

<p>I think one of the more interesting things to point out about this script is that if you’re provisioning a Web Application for Claims versus Classic mode there are differences in how the <em>New-SPWebApplication</em> cmdlet must be called and, when using Claims, there’s more work that needs to be done to make sure the authentication providers are set properly. Outside of that I really think the script is pretty straightforward, if not a bit lengthy. One little hack/cheat that I wanted to point out is my use of the claims prefix, &quot;i:0#.w|&quot; – most of the time my little hack to get this prefix will be more than sufficient but technically, if I wanted my script to be truly generic, I should have done this to get the encoded username (as opposed to just assuming the prefix value and prepending it to the username):</p>

<div style="height: auto" class="codebox">
  <pre><span style="color: #800080">$claim</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> [</span><span style="color: #008080">Microsoft.SharePoint.Administration.Claims.SPClaimProviderManager</span><span style="color: #000000">]::</span><span style="color: #8b4513">CreateUserClaim</span><span style="color: #000000">(</span><span style="color: #800000">&quot;</span><span style="color: #800000">isclondon\spcacheuser</span><span style="color: #800000">&quot;</span><span style="color: #000000">, </span><span style="color: #800000">&quot;</span><span style="color: #800000">Windows</span><span style="color: #800000">&quot;</span><span style="color: #000000">)
[</span><span style="color: #008080">Microsoft.SharePoint.Administration.Claims.SPClaimProviderManager</span><span style="color: #000000">]::</span><span style="color: #8b4513">Local</span><span style="color: #000000">.</span><span style="color: #8b4513">EncodeClaim</span><span style="color: #000000">(</span><span style="color: #800080">$claim</span><span style="color: #000000">)</span></pre>
</div>

<h2>SecureStoreServices.ps1</h2>

<p>The last script that I walked through during the sessions was the <strong>SecureStoreServices.ps1</strong> script. (It would have obviously been impossible to walk through all the Service Application related scripts during a single 1 hour presentation so the presentation itself focused on the general patterns, and lack thereof, and we then walked through this one script as a simple example which ties it all together).</p>

<p>Like all the other scripts this one was driven by another XML file:</p>

<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Farm</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Services</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">SecureStoreServices</span><span class="kwrd">&gt;</span>
          <span class="kwrd">&lt;</span><span class="html">Servers</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Server</span> <span class="attr">Name</span><span class="kwrd">=&quot;SP03&quot;</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Server</span> <span class="attr">Name</span><span class="kwrd">=&quot;SP04&quot;</span> <span class="kwrd">/&gt;</span>
          <span class="kwrd">&lt;/</span><span class="html">Servers</span><span class="kwrd">&gt;</span>
          <span class="kwrd">&lt;</span><span class="html">SecureStoreServiceApplications</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">SecureStoreServiceApplication</span> 
                <span class="attr">Name</span><span class="kwrd">=&quot;ISC Secure Store Service&quot;</span> 
                <span class="attr">DatabaseName</span><span class="kwrd">=&quot;ISC_SecureStore&quot;</span> 
                <span class="attr">DatabaseServer</span><span class="kwrd">=&quot;ISCSharePoint1&quot;</span> 
                <span class="attr">FailoverDatabaseServer</span><span class="kwrd">=&quot;&quot;</span>
                <span class="attr">AuditingEnabled</span><span class="kwrd">=&quot;true&quot;</span> 
                <span class="attr">AuditLogMaxSize</span><span class="kwrd">=&quot;30&quot;</span> 
                <span class="attr">Sharing</span><span class="kwrd">=&quot;false&quot;</span> 
                <span class="attr">KeyPassphrase</span><span class="kwrd">=&quot;p@ssw0rd&quot;</span> 
                <span class="attr">Partitioned</span><span class="kwrd">=&quot;false&quot;</span><span class="kwrd">&gt;</span>
              <span class="kwrd">&lt;</span><span class="html">ApplicationPool</span> <span class="attr">Name</span><span class="kwrd">=&quot;SharePoint Services App Pool&quot;</span> 
                      <span class="attr">AccountName</span><span class="kwrd">=&quot;isclondon\SPServices&quot;</span> 
                    <span class="attr">AccountPassword</span><span class="kwrd">=&quot;password&quot;</span> <span class="kwrd">/&gt;</span>
              <span class="kwrd">&lt;</span><span class="html">Proxy</span> <span class="attr">Name</span><span class="kwrd">=&quot;ISC Secure Store Service&quot;</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">ProxyGroup</span> <span class="attr">Name</span><span class="kwrd">=&quot;Default&quot;</span> <span class="kwrd">/&gt;</span>
              <span class="kwrd">&lt;/</span><span class="html">Proxy</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">SecureStoreServiceApplication</span><span class="kwrd">&gt;</span>
          <span class="kwrd">&lt;/</span><span class="html">SecureStoreServiceApplications</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">SecureStoreServices</span><span class="kwrd">&gt;</span>    
    <span class="kwrd">&lt;/</span><span class="html">Services</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Farm</span><span class="kwrd">&gt;</span></pre>



<p>Hopefully you’ve picked up on the fact that the XML node structure is such that you could easily stitch all the XML files together into a single XML file which would be easier to maintain (think search and replace); I’ve intentionally structured my scripts and XML files for this conference so that they are all essentially standalone which made walking through the code in a presentation much easier as there was a lot less context switching. For my personal scripts I use a series of shared library scripts where I’ve put common functions and all my XML is contained in one XML file (which I manage using a custom WPF application that I’ve developed).</p>

<p>Time for the actual script:</p>

<div class="codebox">
  <pre><span style="color: #0000ff">function</span><span style="color: #000000"> </span><span style="color: #5f9ea0">Start-SecureStoreServices</span><span style="color: #000000"> {
    [CmdletBinding()]
    </span><span style="color: #0000ff">param</span><span style="color: #000000"> 
    (  
        [Parameter(Mandatory</span><span style="color: #ff0000">=</span><span style="color: #800080">$true</span><span style="color: #000000">, Position</span><span style="color: #ff0000">=</span><span style="color: #000000">0</span><span style="color: #000000">)]
        [ValidateNotNullOrEmpty()]
        [</span><span style="color: #008080">string</span><span style="color: #000000">]</span><span style="color: #800080">$SettingsFile</span><span style="color: #000000">
    )
    
    [</span><span style="color: #008080">xml</span><span style="color: #000000">]</span><span style="color: #800080">$config</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-Content</span><span style="color: #000000"> </span><span style="color: #800080">$settingsFile</span><span style="color: #000000">

    </span><span style="color: #800080">$install</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> ((</span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.Services.SecureStoreServices.Servers.Server | </span><span style="color: #5f9ea0; font-weight: bold">where</span><span style="color: #000000"> {</span><span style="color: #800080">$_</span><span style="color: #000000">.Name </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$env:computername</span><span style="color: #000000">}) </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">)
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #ff0000">!</span><span style="color: #800080">$install</span><span style="color: #000000">) { 
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Machine not specified in Servers element, service will not be installed on this server.</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #0000ff">return</span><span style="color: #000000">
    }
    
    </span><span style="color: #800080">$svc</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPServiceInstance</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Server</span><span style="color: #000000"> </span><span style="color: #800080">$env:computername</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">where</span><span style="color: #000000"> {</span><span style="color: #800080">$_</span><span style="color: #000000">.TypeName </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Secure Store Service</span><span style="color: #800000">&quot;</span><span style="color: #000000">}
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$svc</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
        </span><span style="color: #0000ff">throw</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Unable to retrieve Service Instance.</span><span style="color: #800000">&quot;</span><span style="color: #000000">
    }
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$svc</span><span style="color: #000000">.Status </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Online</span><span style="color: #800000">&quot;</span><span style="color: #000000">) {
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Starting service instance...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #800080">$svc</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">Start-SPServiceInstance</span><span style="color: #000000">
    
        </span><span style="color: #008000">#</span><span style="color: #008000">Make sure the service is online before attempting to add a svc app.</span><span style="color: #008000">
</span><span style="color: #000000">        </span><span style="color: #0000ff">while</span><span style="color: #000000"> (</span><span style="color: #800080">$true</span><span style="color: #000000">) {
            </span><span style="color: #5f9ea0; font-weight: bold">Start-Sleep</span><span style="color: #000000"> </span><span style="color: #000000">2</span><span style="color: #000000">
            </span><span style="color: #800080">$svc</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPServiceInstance</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Server</span><span style="color: #000000"> </span><span style="color: #800080">$env:computername</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">where</span><span style="color: #000000"> {</span><span style="color: #800080">$_</span><span style="color: #000000">.TypeName </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Secure Store Service</span><span style="color: #800000">&quot;</span><span style="color: #000000">}
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$svc</span><span style="color: #000000">.Status </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Online</span><span style="color: #800000">&quot;</span><span style="color: #000000">) { </span><span style="color: #0000ff">break</span><span style="color: #000000"> }
        }
    }


    </span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (</span><span style="color: #800080">$appConfig</span><span style="color: #000000"> </span><span style="color: #0000ff">in</span><span style="color: #000000"> </span><span style="color: #800080">$config</span><span style="color: #000000">.Farm.Services.SecureStoreServices.SecureStoreServiceApplications.SecureStoreServiceApplication) {
        </span><span style="color: #800080">$app</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPServiceApplication</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">where</span><span style="color: #000000"> {</span><span style="color: #800080">$_</span><span style="color: #000000">.Name </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$appConfig</span><span style="color: #000000">.Name}
        </span><span style="color: #800080">$updateKey</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$false</span><span style="color: #000000">
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$app</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
            </span><span style="color: #800080">$poolName</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$appConfig</span><span style="color: #000000">.ApplicationPool.Name
            </span><span style="color: #800080">$identity</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$appConfig</span><span style="color: #000000">.ApplicationPool.AccountName
            </span><span style="color: #800080">$password</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$appConfig</span><span style="color: #000000">.ApplicationPool.AccountPassword
            </span><span style="color: #800080">$pool</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> Get-ServicePool </span><span style="color: #800080">$poolName</span><span style="color: #000000"> </span><span style="color: #800080">$identity</span><span style="color: #000000"> </span><span style="color: #800080">$password</span><span style="color: #000000">

            </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Creating secure store service application...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            </span><span style="color: #800080">$app</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-SPSecureStoreServiceApplication</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Name</span><span style="color: #000000"> </span><span style="color: #800080">$appConfig</span><span style="color: #000000">.Name </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-ApplicationPool</span><span style="color: #000000"> </span><span style="color: #800080">$pool</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-DatabaseServer</span><span style="color: #000000"> </span><span style="color: #800080">$appConfig</span><span style="color: #000000">.DatabaseServer </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-DatabaseName</span><span style="color: #000000"> </span><span style="color: #800080">$appConfig</span><span style="color: #000000">.DatabaseName </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-AuditingEnabled</span><span style="color: #000000"> <img src='http://blog.falchionconsulting.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> [</span><span style="color: #008080">bool</span><span style="color: #000000">]::</span><span style="color: #8b4513">Parse</span><span style="color: #000000">(</span><span style="color: #800080">$appConfig</span><span style="color: #000000">.AuditingEnabled)) </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                -AuditLogMaxSize </span><span style="color: #800080">$appConfig</span><span style="color: #000000">.AuditLogMaxSize </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                -FailoverDatabaseServer </span><span style="color: #800080">$appConfig</span><span style="color: #000000">.FailoverDatabaseServer </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                -PartitionMode:([</span><span style="color: #008080">bool</span><span style="color: #000000">]::</span><span style="color: #8b4513">Parse</span><span style="color: #000000">(</span><span style="color: #800080">$appConfig</span><span style="color: #000000">.Partitioned)) </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                -Sharing:([</span><span style="color: #008080">bool</span><span style="color: #000000">]::</span><span style="color: #8b4513">Parse</span><span style="color: #000000">(</span><span style="color: #800080">$appConfig</span><span style="color: #000000">.Sharing))
            </span><span style="color: #800080">$updateKey</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$true</span><span style="color: #000000">
        } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
            </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Secure store service application already exists, skipping creation.</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        }

        </span><span style="color: #800080">$proxy</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPServiceApplicationProxy</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">where</span><span style="color: #000000"> {</span><span style="color: #800080">$_</span><span style="color: #000000">.Name </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$appConfig</span><span style="color: #000000">.Proxy.Name}
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$proxy</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
            </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Creating secure store service application proxy...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            </span><span style="color: #800080">$proxy</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-SPSecureStoreServiceApplicationProxy</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-Name</span><span style="color: #000000"> </span><span style="color: #800080">$appConfig</span><span style="color: #000000">.Proxy.Name </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-ServiceApplication</span><span style="color: #000000"> </span><span style="color: #800080">$app</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">`</span><span style="color: #000000">
                </span><span style="font-style: italic; color: #5f9ea0">-DefaultProxyGroup</span><span style="color: #000000">:</span><span style="color: #800080">$false</span><span style="color: #000000">
        } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
            </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Secure store service application proxy already exists, skipping creation.</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        }
        </span><span style="color: #800080">$proxy</span><span style="color: #000000"> | Set-ProxyGroupsMembership </span><span style="color: #800080">$appConfig</span><span style="color: #000000">.Proxy.ProxyGroup

        
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$updateKey</span><span style="color: #000000">) {
            </span><span style="color: #5f9ea0; font-weight: bold">Update-SPSecureStoreMasterKey</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ServiceApplicationProxy</span><span style="color: #000000"> </span><span style="color: #800080">$proxy</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Passphrase</span><span style="color: #000000"> </span><span style="color: #800080">$appConfig</span><span style="color: #000000">.KeyPassphrase
            </span><span style="color: #0000ff">while</span><span style="color: #000000"> (</span><span style="color: #800080">$true</span><span style="color: #000000">) {
                </span><span style="color: #0000ff">try</span><span style="color: #000000"> {
                    </span><span style="color: #5f9ea0; font-weight: bold">Start-Sleep</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Seconds</span><span style="color: #000000"> </span><span style="color: #000000">5</span><span style="color: #000000">
                    </span><span style="color: #5f9ea0; font-weight: bold">Update-SPSecureStoreApplicationServerKey</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ServiceApplicationProxy</span><span style="color: #000000"> </span><span style="color: #800080">$proxy</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Passphrase</span><span style="color: #000000"> </span><span style="color: #800080">$appConfig</span><span style="color: #000000">.KeyPassphrase
                    </span><span style="color: #0000ff">break</span><span style="color: #000000">
                } </span><span style="color: #0000ff">catch</span><span style="color: #000000"> { }
            }
        }
        
    }
}



</span><span style="color: #0000ff">function</span><span style="color: #000000"> </span><span style="color: #5f9ea0">Get-ServicePool</span><span style="color: #000000">(</span><span style="color: #800080">$poolName</span><span style="color: #000000">, </span><span style="color: #800080">$identity</span><span style="color: #000000">, </span><span style="color: #800080">$password</span><span style="color: #000000">) {
    </span><span style="color: #800080">$pool</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPServiceApplicationPool</span><span style="color: #000000"> </span><span style="color: #800080">$poolName</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000">
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$pool</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$identity</span><span style="color: #000000"> </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
            </span><span style="color: #800080">$acct</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPManagedAccount</span><span style="color: #000000"> </span><span style="color: #800080">$identity</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000">
        }
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$acct</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> ([</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$password</span><span style="color: #000000">)) {
                </span><span style="color: #800080">$cred</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-Credential</span><span style="color: #000000"> </span><span style="color: #800080">$identity</span><span style="color: #000000">
            } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
                </span><span style="color: #800080">$cred</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-Object</span><span style="color: #000000"> </span><span style="color: #800000">System.Management.Automation.PSCredential</span><span style="color: #000000"> </span><span style="color: #800080">$identity</span><span style="color: #000000">, (</span><span style="color: #5f9ea0; font-weight: bold">ConvertTo-SecureString</span><span style="color: #000000"> </span><span style="color: #800080">$password</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-AsPlainText</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-force</span><span style="color: #000000">)
            }
            </span><span style="color: #800080">$acct</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPManagedAccount</span><span style="color: #000000"> </span><span style="color: #800080">$cred</span><span style="color: #000000">.UserName </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000">
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$acct</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
                </span><span style="color: #800080">$acct</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-SPManagedAccount</span><span style="color: #000000"> </span><span style="color: #800080">$cred</span><span style="color: #000000">
            }
        }
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Creating application pool...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #800080">$pool</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-SPServiceApplicationPool</span><span style="color: #000000">  </span><span style="font-style: italic; color: #5f9ea0">-Name</span><span style="color: #000000"> </span><span style="color: #800080">$poolName</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Account</span><span style="color: #000000"> </span><span style="color: #800080">$acct</span><span style="color: #000000">
    }
    </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #800080">$pool</span><span style="color: #000000">
}

</span><span style="color: #0000ff">function</span><span style="color: #000000"> </span><span style="color: #5f9ea0">Set-ProxyGroupsMembership</span><span style="color: #000000">([</span><span style="color: #008080">System.Xml.XmlElement</span><span style="color: #000000">[]]</span><span style="color: #800080">$groups</span><span style="color: #000000">, [</span><span style="color: #008080">Microsoft.SharePoint.Administration.SPServiceApplicationProxy</span><span style="color: #000000">[]]</span><span style="color: #800080">$InputObject</span><span style="color: #000000">) {
    </span><span style="color: #0000ff">begin</span><span style="color: #000000"> {}
    </span><span style="color: #0000ff">process</span><span style="color: #000000"> {
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$_</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000"> </span><span style="color: #ff0000">-and</span><span style="color: #000000"> </span><span style="color: #800080">$InputObject</span><span style="color: #000000"> </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
            </span><span style="color: #800080">$InputObject</span><span style="color: #000000"> | </span><span style="color: #5f9ea0">Set-ProxyGroupsMembership</span><span style="color: #000000"> </span><span style="color: #800080">$groups</span><span style="color: #000000">
            </span><span style="color: #0000ff">return</span><span style="color: #000000">
        }
        </span><span style="color: #800080">$proxy</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$_</span><span style="color: #000000">
        
        </span><span style="color: #008000">#</span><span style="color: #008000">Clear any existing proxy group assignments</span><span style="color: #008000">
</span><span style="color: #000000">        </span><span style="color: #5f9ea0; font-weight: bold">Get-SPServiceApplicationProxyGroup</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">where</span><span style="color: #000000"> {</span><span style="color: #800080">$_</span><span style="color: #000000">.Proxies </span><span style="color: #ff0000">-contains</span><span style="color: #000000"> </span><span style="color: #800080">$proxy</span><span style="color: #000000">} | </span><span style="color: #5f9ea0; font-weight: bold">ForEach-Object</span><span style="color: #000000"> {
            </span><span style="color: #800080">$proxyGroupName</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$_</span><span style="color: #000000">.Name
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> ([</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$proxyGroupName</span><span style="color: #000000">)) { </span><span style="color: #800080">$proxyGroupName</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Default</span><span style="color: #800000">&quot;</span><span style="color: #000000"> }
            </span><span style="color: #800080">$group</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">
            [</span><span style="color: #008080">bool</span><span style="color: #000000">]</span><span style="color: #800080">$matchFound</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$false</span><span style="color: #000000">
            </span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (</span><span style="color: #800080">$g</span><span style="color: #000000"> </span><span style="color: #0000ff">in</span><span style="color: #000000"> </span><span style="color: #800080">$groups</span><span style="color: #000000">) {
                </span><span style="color: #800080">$group</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$g</span><span style="color: #000000">.Name
                </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$group</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$proxyGroupName</span><span style="color: #000000">) { 
                    </span><span style="color: #800080">$matchFound</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$true</span><span style="color: #000000">
                    </span><span style="color: #0000ff">break</span><span style="color: #000000"> 
                }
            }
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #ff0000">!</span><span style="color: #800080">$matchFound</span><span style="color: #000000">) {
                </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Removing </span><span style="color: #800000">&quot;&quot;</span><span style="color: #800000">$($proxy.DisplayName)</span><span style="color: #800000">&quot;&quot;</span><span style="color: #800000"> from </span><span style="color: #800000">&quot;&quot;</span><span style="color: #800000">$proxyGroupName</span><span style="color: #800000">&quot;&quot;&quot;</span><span style="color: #000000">
                </span><span style="color: #800080">$_</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">Remove-SPServiceApplicationProxyGroupMember</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Member</span><span style="color: #000000"> </span><span style="color: #800080">$proxy</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Confirm</span><span style="color: #000000">:</span><span style="color: #800080">$false</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000">
            }
        }
        
        </span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (</span><span style="color: #800080">$g</span><span style="color: #000000"> </span><span style="color: #0000ff">in</span><span style="color: #000000"> </span><span style="color: #800080">$groups</span><span style="color: #000000">) {
            </span><span style="color: #800080">$group</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$g</span><span style="color: #000000">.Name

            </span><span style="color: #800080">$pg</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$group</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Default</span><span style="color: #800000">&quot;</span><span style="color: #000000"> </span><span style="color: #ff0000">-or</span><span style="color: #000000"> [</span><span style="color: #008080">string</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsNullOrEmpty</span><span style="color: #000000">(</span><span style="color: #800080">$group</span><span style="color: #000000">)) {
                </span><span style="color: #800080">$pg</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> [</span><span style="color: #008080">Microsoft.SharePoint.Administration.SPServiceApplicationProxyGroup</span><span style="color: #000000">]::</span><span style="color: #8b4513">Default</span><span style="color: #000000">
            } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
                </span><span style="color: #800080">$pg</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">Get-SPServiceApplicationProxyGroup</span><span style="color: #000000"> </span><span style="color: #800080">$group</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ErrorVariable</span><span style="color: #000000"> </span><span style="color: #800000">err</span><span style="color: #000000">
                </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$pg</span><span style="color: #000000"> </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
                    </span><span style="color: #800080">$pg</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-SPServiceApplicationProxyGroup</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Name</span><span style="color: #000000"> </span><span style="color: #800080">$name</span><span style="color: #000000">
                }
            }
            
            </span><span style="color: #800080">$pg</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$pg</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">where</span><span style="color: #000000"> {</span><span style="color: #800080">$_</span><span style="color: #000000">.Proxies </span><span style="color: #ff0000">-notcontains</span><span style="color: #000000"> </span><span style="color: #800080">$proxy</span><span style="color: #000000">}
            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$pg</span><span style="color: #000000"> </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) { 
                </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Adding </span><span style="color: #800000">&quot;&quot;</span><span style="color: #800000">$($proxy.DisplayName)</span><span style="color: #800000">&quot;&quot;</span><span style="color: #800000"> to </span><span style="color: #800000">&quot;&quot;</span><span style="color: #800000">$($pg.DisplayName)</span><span style="color: #800000">&quot;&quot;&quot;</span><span style="color: #000000">
                </span><span style="color: #800080">$pg</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">Add-SPServiceApplicationProxyGroupMember</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Member</span><span style="color: #000000"> </span><span style="color: #800080">$proxy</span><span style="color: #000000"> 
            }
        }
    }
    </span><span style="color: #0000ff">end</span><span style="color: #000000"> {}
}</span></pre>
</div>

<p>&#160;</p>

<p>Again, I’m not going to explain what’s going on in this script – my book covers it in detail.</p>

<h2>Final Thoughts</h2>

<p>So on that final note about my book I’d like to reiterate that everything I demoed during the conference and virtually everything that my scripts did to provision the conference Farm is detailed in great depth in my <em><a href="http://www.amazon.com/dp/0470939206?tag=shareautom-20&amp;camp=213381&amp;creative=390973&amp;linkCode=as4&amp;creativeASIN=0470939206&amp;adid=17CM1D6656TPW4XXP0FF&amp;&amp;ref-refURL=http%3A%2F%2Fblog.falchionconsulting.com%2F" target="_blank">Automating Microsoft SharePoint 2010 Administration with Windows PowerShell 2.0</a></em> book (I don’t cover the Office Web Applications in the book). Not only that, but most of the scripts are also available for download as part of the book. Are all of them available? <strong><em>No</em></strong>. Why? Because I’m a self employed consultant who needs to be able to provide for my family and if I give away everything I ever produce then I’ll slowly be putting myself out of a job and my daughter can forget about going to college so please, please, please do not ask me to post the full scripts because it’s simply not going to happen – if you want the full scripts then hire me to build your Farm or talk to me about purchasing my SharePoint 2010 Farm Builder application. (I know during the conference people were tweeting and blogging that I would be providing all my scripts – I never said I would do this – I simply said that I would provide the scripts which I walked through during the session and this is what I have done in this post).</p>

<p>To those that attended my sessions I truly hope you got some value out of the content that Spence, Chan and I provided and I’d like to thank everyone (speakers, organizers, and attendees) for such a wonderful overall event and for making me feel so welcome so far from home. And of course a special thanks to Spence and Chan for all they did to help pull these sessions off.</p>

<p>-Gary</p>]]></content:encoded>
			<wfw:commentRss>http://blog.falchionconsulting.com/index.php/2012/05/international-sharepoint-conference-2012-follow-up/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blog.falchionconsulting.com/index.php/2012/05/international-sharepoint-conference-2012-follow-up/</feedburner:origLink></item>
		<item>
		<title>Exporting and Importing SharePoint 2010 Terms</title>
		<link>http://feedproxy.google.com/~r/AutomatingSharePoint/~3/jPLwoQdye9w/</link>
		<comments>http://blog.falchionconsulting.com/index.php/2012/03/exporting-and-importing-sharepoint-2010-terms/#comments</comments>
		<pubDate>Fri, 16 Mar 2012 23:51:21 +0000</pubDate>
		<dc:creator>Gary Lapointe</dc:creator>
				<category><![CDATA[PowerShell Cmdlets]]></category>
		<category><![CDATA[SharePoint 2010]]></category>
		<category><![CDATA[Cmdlets]]></category>
		<category><![CDATA[Managed Terms]]></category>

		<guid isPermaLink="false">http://blog.falchionconsulting.com/index.php/2012/03/exporting-and-importing-sharepoint-2010-terms/</guid>
		<description><![CDATA[Ever had the need to migrate Terms from the Managed Metadata Term Store from one environment to another? Do you find the flat, CSV, import approach provided out of the box to be insufficient (especially with its lack of support for alternate labels)? When I first started working with Terms over two years ago I [...]]]></description>
			<content:encoded><![CDATA[<p>Ever had the need to migrate Terms from the Managed Metadata Term Store from one environment to another? Do you find the flat, CSV, import approach provided out of the box to be insufficient (especially with its lack of support for alternate labels)? When I first started working with Terms over two years ago I was extremely frustrated by the lack of export and import capabilities so I decided to solve the problem myself by creating two cmdlets, <strong>Export-SPTerms</strong> and <strong>Import-SPTerms</strong>. I’ve actually had these cmdlets publicly available for about two years now but I suspect very few people actually know they exist so I thought I’d put together this short post just to highlight them (I also recently pushed out an update which adds support for Site Collection scoped Groups if you have SP1 deployed).</p>  <p>I don’t want to go into a lot of detail regarding how these cmdlets work as they’re really very simple and the bulk of the code is just about iterating through the Term Store structure and turning the various objects into an XML structure (you can download the code from my downloads page). So with brevity in mind, here’s the full help for the <strong>Export-SPTerms</strong> cmdlet:</p>  <div style="border-bottom: black 1px solid; border-left: black 1px solid; background-color: darkblue; font-family: courier new; height: 400px; color: white; overflow: auto; border-top: black 1px solid; border-right: black 1px solid">   <p>NAME      <br />&#160;&#160;&#160; Export-SPTerms       <br />&#160;&#160;&#160; <br />SYNOPSIS       <br />&#160;&#160;&#160; Export the Managed Metadata Terms.       <br />&#160;&#160;&#160; <br />SYNTAX       <br />&#160;&#160;&#160; Export-SPTerms [-TaxonomySession] &lt;SPTaxonomySessionPipeBind&gt; [[-OutputFile] &lt;String&gt;] [-AssignmentCollection &lt;SPAssignmentCollection&gt;] [&lt;CommonParameters&gt;]       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; Export-SPTerms [-TermStore] &lt;SPTaxonomyTermStorePipeBind&gt; [[-OutputFile] &lt;String&gt;] [-AssignmentCollection &lt;SPAssignmentCollection&gt;] [&lt;CommonParameters&gt;]       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; Export-SPTerms [-Group] &lt;SPTaxonomyGroupPipeBind&gt; [[-OutputFile] &lt;String&gt;] [-AssignmentCollection &lt;SPAssignmentCollection&gt;] [&lt;CommonParameters&gt;]       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; Export-SPTerms [-TermSet] &lt;SPTaxonomyTermSetPipeBind&gt; [[-OutputFile] &lt;String&gt;] [-AssignmentCollection &lt;SPAssignmentCollection&gt;] [&lt;CommonParameters&gt;]       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; Export-SPTerms [-Term] &lt;SPTaxonomyTermPipeBind&gt; [[-OutputFile] &lt;String&gt;] [-AssignmentCollection &lt;SPAssignmentCollection&gt;] [&lt;CommonParameters&gt;]       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />DESCRIPTION       <br />&#160;&#160;&#160; Export the Managed Metadata Terms.       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; Copyright 2011 Falchion Consulting, LLC       <br />&#160;&#160;&#160; &gt; For more information on this cmdlet and others:       <br />&#160;&#160;&#160; &gt;http://blog.falchionconsulting.com/       <br />&#160;&#160;&#160; &gt; Use of this cmdlet is at your own risk.       <br />&#160;&#160;&#160; &gt; Gary Lapointe assumes no liability.       <br />&#160;&#160;&#160; </p>    <p>PARAMETERS      <br />&#160;&#160;&#160; -TaxonomySession &lt;SPTaxonomySessionPipeBind&gt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; The TaxonomySession object containing the Term Stores to export.       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; true       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; true (ByValue)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; -TermStore &lt;SPTaxonomyTermStorePipeBind&gt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; The TermStore object containing the terms to export.       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; true       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; true (ByValue, ByPropertyName)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; -Group &lt;SPTaxonomyGroupPipeBind&gt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; The Group object containing the terms to export.       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; true       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; true (ByValue, ByPropertyName)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; -TermSet &lt;SPTaxonomyTermSetPipeBind&gt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; The TermSet object containing the terms to export.       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; true       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; true (ByValue, ByPropertyName)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; -Term &lt;SPTaxonomyTermPipeBind&gt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; The Term object containing the terms to export.       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; true       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; true (ByValue, ByPropertyName)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; -OutputFile [&lt;String&gt;]       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; The path to the file to save the terms to.       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 2       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; -AssignmentCollection [&lt;SPAssignmentCollection&gt;]       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Manages objects for the purpose of proper disposal. Use of objects, such as SPWeb or SPSite, can use large amounts of memory and use of these objects in Windows PowerShell scripts requires proper memory management. Using the SPAssignment object, you can assign objects to a variable and dispose of the objects after they are needed to free up memory. When SPWeb, SPSite, or SPSiteAdministration objects are used, the objects are automatically disposed of if an assignment collection or the Global parameter is not used.       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; When the Global parameter is used, all objects are contained in the global store. If objects are not immediately used, or disposed of by using the Stop-SPAssignment command, an out-of-memory scenario can occur.       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; named       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; true (ByValue)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; &lt;CommonParameters&gt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; This cmdlet supports the common parameters: Verbose, Debug,       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ErrorAction, ErrorVariable, WarningAction, WarningVariable,       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; OutBuffer and OutVariable. For more information, type,       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &quot;get-help about_commonparameters&quot;.       <br />&#160;&#160;&#160; <br />INPUTS       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />OUTPUTS       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />NOTES       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; For more information, type &quot;Get-Help Export-SPTerms -detailed&quot;. For technical information, type &quot;Get-Help Export-SPTerms -full&quot;.       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; ------------------EXAMPLE 1-----------------------       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; PS C:\&gt; Export-SPTerms -TaxonomySession &quot;http://site/&quot; -OutputFile &quot;c:\terms.xml&quot;       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; This example exports the terms for all term stores associated with the site and saves to c:\terms.xml.       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; ------------------EXAMPLE 2-----------------------       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; PS C:\&gt; Export-SPTerms -Group (Get-SPTaxonomySession -Site &quot;http://site/&quot;).TermStores[0].Groups[0] -OutputFile &quot;c:\terms.xml&quot;       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; This example exports the first Group of the first Term Store and saves to c:\terms.xml.       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />RELATED LINKS       <br />&#160;&#160;&#160; Import-SPTerms       <br />&#160;&#160;&#160; Get-SPTaxonomySession</p> </div>  <p>&#160;</p>  <p>Now lets look at the <strong>Import-SPTerms</strong> cmdlet (it’s very similar):</p>  <div style="border-bottom: black 1px solid; border-left: black 1px solid; background-color: darkblue; font-family: courier new; height: 400px; color: white; overflow: auto; border-top: black 1px solid; border-right: black 1px solid">   <p>     <br />NAME       <br />&#160;&#160;&#160; Import-SPTerms       <br />&#160;&#160;&#160; <br />SYNOPSIS       <br />&#160;&#160;&#160; Import the Managed Metadata Terms.       <br />&#160;&#160;&#160; <br />SYNTAX       <br />&#160;&#160;&#160; Import-SPTerms [-TaxonomySession] &lt;SPTaxonomySessionPipeBind&gt; [-InputFile] &lt;XmlDocumentPipeBind&gt; [-AssignmentCollection &lt;SPAssignmentCollection&gt;] [&lt;CommonParameters&gt;]       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; Import-SPTerms [-ParentTermStore] &lt;SPTaxonomyTermStorePipeBind&gt; [-InputFile] &lt;XmlDocumentPipeBind&gt; [-AssignmentCollection &lt;SPAssignmentCollection&gt;] [&lt;CommonParameters&gt;]       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; Import-SPTerms [-ParentGroup] &lt;SPTaxonomyGroupPipeBind&gt; [-InputFile] &lt;XmlDocumentPipeBind&gt; [-AssignmentCollection &lt;SPAssignmentCollection&gt;] [&lt;CommonParameters&gt;]       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; Import-SPTerms [-ParentTermSet] &lt;SPTaxonomyTermSetPipeBind&gt; [-InputFile] &lt;XmlDocumentPipeBind&gt; [-AssignmentCollection &lt;SPAssignmentCollection&gt;] [&lt;CommonParameters&gt;]       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; Import-SPTerms [-ParentTerm] &lt;SPTaxonomyTermPipeBind&gt; [-InputFile] &lt;XmlDocumentPipeBind&gt; [-AssignmentCollection &lt;SPAssignmentCollection&gt;] [&lt;CommonParameters&gt;]       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />DESCRIPTION       <br />&#160;&#160;&#160; Import the Managed Metadata Terms.       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; Copyright 2011 Falchion Consulting, LLC       <br />&#160;&#160;&#160; &gt; For more information on this cmdlet and others:       <br />&#160;&#160;&#160; &gt; http://blog.falchionconsulting.com/       <br />&#160;&#160;&#160; &gt; Use of this cmdlet is at your own risk.       <br />&#160;&#160;&#160; &gt; Gary Lapointe assumes no liability.       <br />&#160;&#160;&#160; </p>    <p>PARAMETERS      <br />&#160;&#160;&#160; -TaxonomySession &lt;SPTaxonomySessionPipeBind&gt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; The TaxonomySession object to import Term Stores into.       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; true       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; true (ByValue)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; -ParentTermStore &lt;SPTaxonomyTermStorePipeBind&gt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; The TermStore object to import Groups into.       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; true       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; true (ByValue, ByPropertyName)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; -ParentGroup &lt;SPTaxonomyGroupPipeBind&gt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; The Group object to import Term Sets into.       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; true       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; true (ByValue, ByPropertyName)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; -ParentTermSet &lt;SPTaxonomyTermSetPipeBind&gt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; The TermSet object to import Terms into.       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; true       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; true (ByValue, ByPropertyName)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; -ParentTerm &lt;SPTaxonomyTermPipeBind&gt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; The Term object to import Terms into.       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; true       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; true (ByValue, ByPropertyName)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; -InputFile &lt;XmlDocumentPipeBind&gt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; The path to the file containing the terms to import or an XmlDocument object or XML string.       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; true       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 2       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; true (ByValue)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; -AssignmentCollection [&lt;SPAssignmentCollection&gt;]       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Manages objects for the purpose of proper disposal. Use of objects, such as SPWeb or SPSite, can use large amounts of memory and use of these objects in Windows PowerShell scripts requires proper memory management. Using the SPAssignment object, you can assign objects to a variable and dispose of the objects after they are needed to free up memory. When SPWeb, SPSite, or SPSiteAdministration objects are used, the objects are automatically disposed of if an assignment collection or the Global parameter is not used.       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; When the Global parameter is used, all objects are contained in the global store. If objects are not immediately used, or disposed of by using the Stop-SPAssignment command, an out-of-memory scenario can occur.       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; named       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; true (ByValue)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; &lt;CommonParameters&gt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; This cmdlet supports the common parameters: Verbose, Debug,       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ErrorAction, ErrorVariable, WarningAction, WarningVariable,       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; OutBuffer and OutVariable. For more information, type,       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &quot;get-help about_commonparameters&quot;.       <br />&#160;&#160;&#160; <br />INPUTS       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />OUTPUTS       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />NOTES       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; For more information, type &quot;Get-Help Import-SPTerms -detailed&quot;. For technical information, type &quot;Get-Help Import-SPTerms -full&quot;.       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; ------------------EXAMPLE 1-----------------------       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; PS C:\&gt; Import-SPTerms -ParentTermStore (Get-SPTaxonomySession -Site &quot;http://site/&quot;).TermStores[0] -InputFile &quot;c:\terms.xml&quot;       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; This example imports the Group from c:\terms.xml to the first Term Store.       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; ------------------EXAMPLE 2-----------------------       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; PS C:\&gt; Import-SPTerms -TaxonomySession &quot;http://site/&quot; -InputFile &quot;c:\terms.xml&quot;       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; This example imports the terms from c:\terms.xml to the Term Store associated with http://site.       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; <br />RELATED LINKS       <br />&#160;&#160;&#160; Export-SPTerms       <br />&#160;&#160;&#160; Get-SPTaxonomySession       <br /></p> </div>  <p>&#160;</p>  <p>Using these cmdlets I can easily export terms from one environment, such as production, to another environment, such as my test environment. This avoids the need to have backup and restore the database associated with the term store (which requires removing and re-provisioning the service application. And the way I’ve written the cmdlets all the Term Set, Group, and Term IDs remain consistent and, because the exported XML is easily modified, when it comes to Site Collection scoped Groups you can do a simple search and replace to change Site Collection URLs to match the new target (note that I first check for a Site Collection with the specified URL and if not found then I use the ID and if I still can’t locate the Site Collection then I create the Group as a standard shared Group).</p>  <p>-Gary</p>]]></content:encoded>
			<wfw:commentRss>http://blog.falchionconsulting.com/index.php/2012/03/exporting-and-importing-sharepoint-2010-terms/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blog.falchionconsulting.com/index.php/2012/03/exporting-and-importing-sharepoint-2010-terms/</feedburner:origLink></item>
		<item>
		<title>“Stamping” PDF Files Downloaded from SharePoint 2010</title>
		<link>http://feedproxy.google.com/~r/AutomatingSharePoint/~3/gsTcDeEuXU8/</link>
		<comments>http://blog.falchionconsulting.com/index.php/2012/03/stamping-pdf-files-downloaded-from-sharepoint-2010/#comments</comments>
		<pubDate>Sun, 11 Mar 2012 23:27:00 +0000</pubDate>
		<dc:creator>Gary Lapointe</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[SharePoint 2010]]></category>
		<category><![CDATA[IHttpHandler]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[SharePoint Foundation 2010]]></category>

		<guid isPermaLink="false">http://blog.falchionconsulting.com/index.php/2012/03/stamping-pdf-files-downloaded-from-sharepoint-2010/</guid>
		<description><![CDATA[First off I want to clarify that the subject of this post is not my idea as it is something that my friend Roman Kobzarev put together for his company and I merely assisted with getting the code to work. The problem that Roman was trying to solve was that his company provided numerous PDF [...]]]></description>
			<content:encoded><![CDATA[<p>First off I want to clarify that the subject of this post is not my idea as it is something that my friend Roman Kobzarev put together for his company and I merely assisted with getting the code to work. The problem that Roman was trying to solve was that his company provided numerous PDF files that registered/paying members could download and, unfortunately, they were finding some of those files being posted to various other sites without their permission; so in an attempt to at least discourage this they wanted to stamp the PDF files with some information about the user who downloaded the file.</p>  <p>There are various ways in which this problem can be solved but perhaps one of the simpler approaches, and the approach outlined here, was to create an HTTP Handler which intercepted requests for any PDF files and then simply retrieve the file from SharePoint, modify it, and then send it on its way. The cool thing about this approach and the pattern shown here is that it can easily be applied to any file type which requires some user or request specific modifications applied to it.</p>  <p>Before I get to the actual code I want to point out one third party dependency that we used: <a href="http://sourceforge.net/projects/itextsharp/" target="_blank">iTextSharp</a>. This is an open source .NET library for PDF generation and manipulation. There are many options available when looking to manipulate PDF files and in this case this one was chosen due to its cost (free). So let’s get to the code.</p>  <p>In terms of code there really isn’t that much which is what makes this such a nice solution. The first piece is the actual implementation of the <font face="Courier New">IHttpHandler</font> interface:</p>  <pre style="border-bottom: black 1px solid; border-left: black 1px solid; width: 100%; height: 400px; overflow: auto; border-top: black 1px solid; border-right: black 1px solid" class="code"><span style="color: blue">using </span>System.IO;
<span style="color: blue">using </span>System.Web;
<span style="color: blue">using </span>Microsoft.SharePoint;
<span style="color: blue">using </span>iTextSharp.text;
<span style="color: blue">using </span>iTextSharp.text.pdf;

<span style="color: blue">namespace </span>Aptillon.SharePoint.PDFWatermark
{
    <span style="color: blue">public class </span><span style="color: #2b91af">PDFWatermarkHttpHandler </span>: <span style="color: #2b91af">IHttpHandler
    </span>{
        <span style="color: blue">public void </span>ProcessRequest(<span style="color: #2b91af">HttpContext </span>context)
        {

            <span style="color: #2b91af">SPFile </span>file = <span style="color: #2b91af">SPContext</span>.Current.Web.GetFile(context.Request.Url.ToString());
            <span style="color: blue">byte</span>[] content = file.OpenBinary();
            <span style="color: #2b91af">SPUser </span>currentUser = <span style="color: #2b91af">SPContext</span>.Current.Web.CurrentUser;

            <span style="color: blue">string </span>watermark = <span style="color: blue">null</span>;
            <span style="color: blue">if </span>(currentUser != <span style="color: blue">null</span>)
                watermark = <span style="color: #a31515">&quot;This download was specially prepared for &quot; </span>+ currentUser.Name;

            <span style="color: blue">if </span>(watermark != <span style="color: blue">null</span>)
            {
                <span style="color: #2b91af">PdfReader </span>pdfReader = <span style="color: blue">new </span><span style="color: #2b91af">PdfReader</span>(content);
                <span style="color: blue">using </span>(<span style="color: #2b91af">MemoryStream </span>outputStream = <span style="color: blue">new </span><span style="color: #2b91af">MemoryStream</span>())
                <span style="color: blue">using </span>(<span style="color: #2b91af">PdfStamper </span>pdfStamper = <span style="color: blue">new </span><span style="color: #2b91af">PdfStamper</span>(pdfReader, outputStream))
                {
                    <span style="color: blue">for </span>(<span style="color: blue">int </span>pageIndex = 1; pageIndex &lt;= pdfReader.NumberOfPages; pageIndex++)
                    {
                        <span style="color: green">//Rectangle class in iText represent geometric representation... 
                        //in this case, rectangle object would contain page geometry
                        </span><span style="color: #2b91af">Rectangle </span>pageRectangle = pdfReader.GetPageSizeWithRotation(pageIndex);
                        <span style="color: green">//PdfContentByte object contains graphics and text content of page returned by PdfStamper
                        </span><span style="color: #2b91af">PdfContentByte </span>pdfData = pdfStamper.GetUnderContent(pageIndex);
                        <span style="color: green">//create font size for watermark
                        </span>pdfData.SetFontAndSize(<span style="color: #2b91af">BaseFont</span>.CreateFont(<span style="color: #2b91af">BaseFont</span>.HELVETICA_BOLD, <span style="color: #2b91af">BaseFont</span>.CP1252, <span style="color: #2b91af">BaseFont</span>.NOT_EMBEDDED), 8);
                        <span style="color: green">//create new graphics state and assign opacity
                        </span><span style="color: #2b91af">PdfGState </span>graphicsState = <span style="color: blue">new </span><span style="color: #2b91af">PdfGState</span>();
                        graphicsState.FillOpacity = 0.4F;
                        <span style="color: green">//set graphics state to PdfContentByte
                        </span>pdfData.SetGState(graphicsState);
                        <span style="color: green">//indicates start of writing of text
                        </span>pdfData.BeginText();
                        <span style="color: green">//show text as per position and rotation
                        </span>pdfData.ShowTextAligned(<span style="color: #2b91af">Element</span>.ALIGN_CENTER, watermark, pageRectangle.Width / 4, pageRectangle.Height / 44, 0);
                        <span style="color: green">//call endText to invalid font set
                        </span>pdfData.EndText();
                    }
                    pdfStamper.Close();
                    content = outputStream.ToArray();
                }
            }
            context.Response.ContentType = <span style="color: #a31515">&quot;application/pdf&quot;</span>;
            context.Response.BinaryWrite(content);
            context.Response.End();
        }

        <span style="color: blue">public bool </span>IsReusable
        {
            <span style="color: blue">get </span>{ <span style="color: blue">return false</span>; }
        }
    }
}</pre>

<p>&#160;</p>

<p>As you can see from the previous code listing, the bulk of the code involves the actual processing of the PDF file but the core SharePoint specific piece is in the beginning of the <font face="Courier New">ProcessRequest()</font> method where we use the <font face="Courier New">SPContext.Current.Web.GetFile()</font> method to retrieve the actual file requested and then, if we can get an actual <font face="Courier New">SPUser</font> object, we create a simple message that will be added to the bottom of the PDF. I’m not going to cover what’s happening with the iTextSharp objects as the point of this article is to demonstrate the pattern which can easily be applied to other file types and not how to use iTextSharp.</p>

<p>To deploy this class I created an empty SharePoint 2010 project using Visual Studio 2010 and added the file to the project. I then created a new Web Application scoped Feature which I use to add the appropriate <strong>web.config</strong> settings which will register the HTTP Handler. The following screenshot shows the final project structure:</p>

<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTML8af78243" border="0" alt="SNAGHTML8af78243" src="http://blog.falchionconsulting.com/wp-content/uploads/2012/03/SNAGHTML8af78243.png" width="392" height="316" /></p>

<p>Note that I also added the <strong>iTextSharp.dll </strong>to the project and added it as an additional assembly to the package by double clicking the <strong>Package.package</strong> element and then, in the package designer, click <strong>Advanced</strong> to add additional assemblies:</p>

<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blog.falchionconsulting.com/wp-content/uploads/2012/03/image.png" width="856" height="168" /></p>

<p>Before I show the code for the Web Application Feature I first want to show what settings I set for the Feature after adding it:</p>

<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blog.falchionconsulting.com/wp-content/uploads/2012/03/image1.png" width="1086" height="609" /></p>

<p>When you add a new Feature to a project it’s going to name it <strong>Feature1</strong> and set the default scope to Web. The first thing I do is rename the Feature to something meaningful – in this case, because I know I’ll only have the one Feature I go ahead and name it the same as the project name: <strong>Aptillon.SharePoint.PDFWatermark</strong> (I always follow the same naming convention for my projects, which equate to WSP file names and Features: &lt;Company&gt;.SharePoint.&lt;Something Appropriate for the Contained Functionality&gt;). The next thing I do is change the <strong>Deployment Path</strong> property for the Feature so that it only uses the Feature name and does not prepend the project name; and finally I set the scope and title of the Feature. Now I’m ready to add my Feature activation event receiver.</p>

<p>The code that I want to include in the event receiver will handle the addition and removal of the web.config handler elements. I do this using the <font face="Courier New">SPWebConfigModification</font> class. Now there’s debate on whether this should be used or not; this is one of those classes where you might say (as my friend Spence Harbar puts it), “Just because you should use it doesn’t mean you can.” The simple explanation for this is that ideally you should be using this class to make web.config modifications but the reality is that this guy is fraught with issues and usually doesn’t work. That said, what I usually do is, where it makes sense, use this class to add and remove my entries but work under the premise that it will probably not work and plan on making these changes manually (or write a timer job which will do what this guy is attempting to do, but that’s out of scope of this article). So here’s the <font face="Courier New">FeatureActivated()</font> and <font face="Courier New">FeatureDeactivating()</font> methods that I use to add and remove the appropriate web.config entries which register the previously defined HTTP Handler:</p>

<pre style="border-bottom: black 1px solid; border-left: black 1px solid; width: 100%; height: 400px; overflow: auto; border-top: black 1px solid; border-right: black 1px solid" class="code"><span style="color: blue">public override void </span>FeatureActivated(<span style="color: #2b91af">SPFeatureReceiverProperties </span>properties)
{
    <span style="color: blue">string </span>asmDetails = <span style="color: blue">typeof</span>(<span style="color: #2b91af">PDFWatermarkHttpHandler</span>).AssemblyQualifiedName;

    <span style="color: #2b91af">SPWebApplication </span>webApp = properties.Feature.Parent <span style="color: blue">as </span><span style="color: #2b91af">SPWebApplication</span>;
    <span style="color: blue">if </span>(webApp == <span style="color: blue">null</span>) <span style="color: blue">return</span>;

    <span style="color: #2b91af">SPWebConfigModification </span>modification = <span style="color: blue">new </span><span style="color: #2b91af">SPWebConfigModification</span>(<span style="color: #a31515">&quot;add[@name=\&quot;PDFWatermark\&quot;]&quot;</span>, <span style="color: #a31515">&quot;configuration/system.webServer/handlers&quot;</span>);
    modification.Value = <span style="color: blue">string</span>.Format(<span style="color: #a31515">&quot;&lt;add name=\&quot;PDFWatermark\&quot; verb=\&quot;*\&quot; path=\&quot;*.pdf\&quot; type=\&quot;</span><span style="color: #3cb371">{0}</span><span style="color: #a31515">\&quot; preCondition=\&quot;integratedMode\&quot; /&gt;&quot;</span>, asmDetails);

    modification.Sequence = 1;
    modification.Owner = asmDetails;
    modification.Type = <span style="color: #2b91af">SPWebConfigModification</span>.<span style="color: #2b91af">SPWebConfigModificationType</span>.EnsureChildNode;
    webApp.WebConfigModifications.Add(modification);

    webApp.Update();
    webApp.WebService.ApplyWebConfigModifications();
}


<span style="color: blue">public override void </span>FeatureDeactivating(<span style="color: #2b91af">SPFeatureReceiverProperties </span>properties)
{
    <span style="color: blue">string </span>asmDetails = <span style="color: blue">typeof</span>(<span style="color: #2b91af">PDFWatermarkHttpHandler</span>).AssemblyQualifiedName;

    <span style="color: #2b91af">SPWebApplication </span>webApp = properties.Feature.Parent <span style="color: blue">as </span><span style="color: #2b91af">SPWebApplication</span>;
    <span style="color: blue">if </span>(webApp == <span style="color: blue">null</span>) <span style="color: blue">return</span>;

    <span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">SPWebConfigModification</span>&gt; configModsFound = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">SPWebConfigModification</span>&gt;();
    <span style="color: #2b91af">Collection</span>&lt;<span style="color: #2b91af">SPWebConfigModification</span>&gt; modsCollection = webApp.WebConfigModifications;
    <span style="color: blue">for </span>(<span style="color: blue">int </span>i = 0; i &lt; modsCollection.Count; i++)
    {
        <span style="color: blue">if </span>(modsCollection[i].Owner == asmDetails)
        {
            configModsFound.Add(modsCollection[i]);
        }
    }

    <span style="color: blue">if </span>(configModsFound.Count &gt; 0)
    {
        <span style="color: blue">foreach </span>(<span style="color: #2b91af">SPWebConfigModification </span>mod <span style="color: blue">in </span>configModsFound)
            modsCollection.Remove(mod);

        webApp.Update();
        webApp.WebService.ApplyWebConfigModifications();
    }
}</pre>

<p>&#160;</p>

<p>With all the code in place I can deploy to my Web Application and now any time a PDF is downloaded I’ll have a nice little message displayed on the bottom of each page. Again, the intent here is to show the simplicity of the pattern and approach – with a little imagination you can easily come up with lots of other uses for this (applying security or password protection to the PDF, adding an image watermark, removing pages based on registration status thus providing “sample” versions, prefilling form fields with user data, adding a version history page, etc.). And of course all this can also be applied to other file types such as the Office files or images (though image handling would take a little more logic to ignore images not coming from document libraries).</p>]]></content:encoded>
			<wfw:commentRss>http://blog.falchionconsulting.com/index.php/2012/03/stamping-pdf-files-downloaded-from-sharepoint-2010/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://blog.falchionconsulting.com/index.php/2012/03/stamping-pdf-files-downloaded-from-sharepoint-2010/</feedburner:origLink></item>
		<item>
		<title>Updating SharePoint 2010 User Information</title>
		<link>http://feedproxy.google.com/~r/AutomatingSharePoint/~3/ueik7IMLEVY/</link>
		<comments>http://blog.falchionconsulting.com/index.php/2011/12/updating-sharepoint-2010-user-information/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 21:51:32 +0000</pubDate>
		<dc:creator>Gary Lapointe</dc:creator>
				<category><![CDATA[PowerShell Scripting]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[SharePoint 2010]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Set-SPUser]]></category>
		<category><![CDATA[SPUser]]></category>
		<category><![CDATA[User Information List]]></category>

		<guid isPermaLink="false">http://blog.falchionconsulting.com/index.php/2011/12/updating-sharepoint-2010-user-information/</guid>
		<description><![CDATA[One of my clients recently had an issue where a particularly high profile user (CEO) had their title spelled incorrectly in Active Directory; unfortunately the error wasn’t noticed right away and now, despite changing the information in Active Directory, SharePoint was still showing the wrong title in the People Picker when granting the user rights [...]]]></description>
			<content:encoded><![CDATA[<p>One of my clients recently had an issue where a particularly high profile user (CEO) had their title spelled incorrectly in Active Directory; unfortunately the error wasn’t noticed right away and now, despite changing the information in Active Directory, SharePoint was still showing the wrong title in the People Picker when granting the user rights to a Site Collection. Fortunately I had a partial PowerShell script to fix the issue and just needed to only slightly modify it – you can see the original script on pages 299 and 300 of <a href="http://www.amazon.com/dp/0470939206?tag=shareautom-20&amp;camp=213381&amp;creative=390973&amp;linkCode=as4&amp;creativeASIN=0470939206&amp;adid=0N73WQ7X6VCZB5V4H95A&amp;&amp;ref-refURL=http%3A%2F%2Fblog.falchionconsulting.com%2F" target="_blank">my book</a>. So before I show the modified script it’s first important to understand the problem and why I needed to use a script and why what I had in the book is somewhat incomplete.</p>  <p>Whenever you grant a user rights to a Site Collection or when that user creates/updates/deletes any item within a Site Collection, an entry for the user will be added to a hidden user information list, if not already there. This “User Information List” is located at <em>http://&lt;SiteCollectionUrl&gt;/_catalogs/users/detail.aspx:</em></p>  <p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTMLa064e71" border="0" alt="SNAGHTMLa064e71" src="http://blog.falchionconsulting.com/wp-content/uploads/2011/12/SNAGHTMLa064e71.png" width="784" height="391" /></p>  <p>By looking at this list you can see that several key pieces of information are stored here – unfortunately, when you change this information in Active Directory the information stored here is not updated (even after running a full or incremental import via UPS). To complicate matters there is no way to edit the information via the browser, thus the need for a PowerShell script. If you click the user’s name you’ll see the additional properties, including an “Edit Item” option, however, the edit dialog is simply a read-only display of the username, helpful right?:</p>  <p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTMLa089b49" border="0" alt="SNAGHTMLa089b49" src="http://blog.falchionconsulting.com/wp-content/uploads/2011/12/SNAGHTMLa089b49.png" width="800" height="317" /></p>  <p>So let’s first consider the scenario that my book addresses and assume that a user had had their name and/or email address changed. To accommodate this scenario we simply use the <a href="http://technet.microsoft.com/en-us/library/ff607827.aspx" target="_blank"><font face="Courier New">Set-SPUser</font></a> cmdlet along with the <font face="Courier New">-SyncFromAD</font> parameter. The following script is taken directly from my book and simply iterates through all Site Collections and calls the <font face="Courier New">Set-SPUser</font> cmdlet for the provided user:</p>  <pre><span style="color: #0000ff">function</span><span style="color: #000000"> </span><span style="color: #5f9ea0">Sync-SPUser</span><span style="color: #000000">([</span><span style="color: #008080">string</span><span style="color: #000000">]</span><span style="color: #800080">$userName</span><span style="color: #000000">) {
  </span><span style="color: #5f9ea0; font-weight: bold">Get-SPSite</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Limit</span><span style="color: #000000"> </span><span style="color: #800000">All</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">foreach</span><span style="color: #000000"> {
    </span><span style="color: #800080">$web</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$_</span><span style="color: #000000">.RootWeb
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$_</span><span style="color: #000000">.WebApplication.UseClaimsAuthentication) {
      </span><span style="color: #800080">$claim</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-SPClaimsPrincipal</span><span style="color: #000000"> </span><span style="color: #800080">$userName</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-IdentityType</span><span style="color: #000000"> </span><span style="color: #800000">WindowsSamAccountName</span><span style="color: #000000">
      </span><span style="color: #800080">$user</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$web</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">Get-SPUser</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Identity</span><span style="color: #000000"> </span><span style="color: #800080">$claim</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000">
    } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
      </span><span style="color: #800080">$user</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$web</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">Get-SPUser</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Identity</span><span style="color: #000000"> </span><span style="color: #800080">$userName</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000">
    }
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$user</span><span style="color: #000000"> </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
      </span><span style="color: #800080">$web</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">Set-SPUser</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Identity</span><span style="color: #000000"> </span><span style="color: #800080">$user</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-SyncFromAD</span><span style="color: #000000">
    }
    </span><span style="color: #800080">$web</span><span style="color: #000000">.Dispose()
    </span><span style="color: #800080">$_</span><span style="color: #000000">.Dispose()
  }
}</span></pre>

<p>&#160;</p>

<p>Before I make any changes to demonstrate this script and the modifications we’ll make to it, let’s first see how my user is currently set in the Site Collection:</p>

<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blog.falchionconsulting.com/wp-content/uploads/2011/12/image.png" width="789" height="662" /></p>

<p>And as shown in the People Picker:</p>

<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTMLa14e91b" border="0" alt="SNAGHTMLa14e91b" src="http://blog.falchionconsulting.com/wp-content/uploads/2011/12/SNAGHTMLa14e91b.png" width="799" height="250" /></p>

<p>Note the “Name”/”Display Name”, “Work e-mail”/”E-Mail”, and “Title” fields.</p>

<p>Now I’ll change these values in Active Directory (make the “p” in my last name capitalized, change the title, and set the email) and then run the script (I saved the script as Sync-SPUser.ps1):</p>

<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTMLa17239b" border="0" alt="SNAGHTMLa17239b" src="http://blog.falchionconsulting.com/wp-content/uploads/2011/12/SNAGHTMLa17239b.png" width="586" height="186" /></p>

<p>(Note that lowercase “p” is the correct spelling for my name, just in case you were wondering <img style="border-bottom-style: none; border-left-style: none; width: 10px; border-top-style: none; height: 10px; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://blog.falchionconsulting.com/wp-content/uploads/2011/12/wlEmoticon-smile.png" />). Now if we look at the user details in the Site Collection and the People Picker we should see the following:</p>

<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blog.falchionconsulting.com/wp-content/uploads/2011/12/image1.png" width="789" height="662" /></p>

<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTMLa1a344d" border="0" alt="SNAGHTMLa1a344d" src="http://blog.falchionconsulting.com/wp-content/uploads/2011/12/SNAGHTMLa1a344d.png" width="800" height="266" /></p>

<p>Notice that the the “Name” / “Display Name” and “Work e-mail” / “E-Mail” fields were updated but not the “Title” field. This is because the <font face="Courier New">Set-SPUser</font> cmdlet and <font face="Courier New">-SyncFromAD</font> parameter only updates these two fields. So how do you update the remaining fields? We simply need to add some code to our function which will grab the <font face="Courier New">SPListItem</font> corresponding to the user from the hidden “User Information List” and then update the corresponding fields manually. The following modified script does this for the “Title” field (note that I’ve changed the function signature to take the title in as a parameter):</p>

<pre><span style="color: #0000ff">function</span><span style="color: #000000"> </span><span style="color: #5f9ea0">Sync-SPUser</span><span style="color: #000000">([</span><span style="color: #008080">string</span><span style="color: #000000">]</span><span style="color: #800080">$userName</span><font style="background-color: #ffff00"><span style="color: #000000">, [</span><span style="color: #008080">string</span><span style="color: #000000">]</span><span style="color: #800080">$title</span></font><span style="color: #000000">) {
  </span><span style="color: #5f9ea0; font-weight: bold">Get-SPSite</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Limit</span><span style="color: #000000"> </span><span style="color: #800000">All</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">foreach</span><span style="color: #000000"> {
    </span><span style="color: #800080">$web</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$_</span><span style="color: #000000">.RootWeb
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$_</span><span style="color: #000000">.WebApplication.UseClaimsAuthentication) {
      </span><span style="color: #800080">$claim</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-SPClaimsPrincipal</span><span style="color: #000000"> </span><span style="color: #800080">$userName</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-IdentityType</span><span style="color: #000000"> </span><span style="color: #800000">WindowsSamAccountName</span><span style="color: #000000">
      </span><span style="color: #800080">$user</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$web</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">Get-SPUser</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Identity</span><span style="color: #000000"> </span><span style="color: #800080">$claim</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000">
    } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
      </span><span style="color: #800080">$user</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$web</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">Get-SPUser</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Identity</span><span style="color: #000000"> </span><span style="color: #800080">$userName</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #800000">SilentlyContinue</span><span style="color: #000000">
    }
    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$user</span><span style="color: #000000"> </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) {
      </span><span style="color: #800080">$web</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">Set-SPUser</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Identity</span><span style="color: #000000"> </span><span style="color: #800080">$user</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-SyncFromAD</span><span style="color: #000000">
      
<font style="background-color: #ffff00">      </font></span><font style="background-color: #ffff00"><span style="color: #800080">$list</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$web</span><span style="color: #000000">.Lists[</span><span style="color: #800000">&quot;</span><span style="color: #800000">User Information List</span><span style="color: #800000">&quot;</span></font><font style="background-color: #ffff00"><span style="color: #000000">]
      </span><span style="color: #800080">$query</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0; font-weight: bold">New-Object</span><span style="color: #000000"> </span><span style="color: #800000">Microsoft.SharePoint.SPQuery</span></font><span style="color: #000000">
<font style="background-color: #ffff00">      </font></span><font style="background-color: #ffff00"><span style="color: #800080">$query</span><span style="color: #000000">.Query </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name='Name' /&gt;&lt;Value Type='Text'&gt;$userName&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;</span><span style="color: #800000">&quot;</span></font><span style="color: #000000">
<font style="background-color: #ffff00">      </font></span><font style="background-color: #ffff00"><span style="color: #0000ff">foreach</span><span style="color: #000000"> (</span><span style="color: #800080">$item</span><span style="color: #000000"> </span><span style="color: #0000ff">in</span><span style="color: #000000"> </span><span style="color: #800080">$list</span><span style="color: #000000">.GetItems(</span><span style="color: #800080">$query</span></font><font style="background-color: #ffff00"><span style="color: #000000">)) {
        </span><span style="color: #800080">$item</span><span style="color: #000000">[</span><span style="color: #800000">&quot;</span><span style="color: #800000">JobTitle</span><span style="color: #800000">&quot;</span><span style="color: #000000">] </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$title</span></font><span style="color: #000000">
<font style="background-color: #ffff00">        </font></span><span style="color: #800080"><font style="background-color: #ffff00">$item</font></span><span style="color: #000000"><font style="background-color: #ffff00">.SystemUpdate()
      }
</font>    }
    </span><span style="color: #800080">$web</span><span style="color: #000000">.Dispose()
    </span><span style="color: #800080">$_</span><span style="color: #000000">.Dispose()
  }
}
</span></pre>

<p>The changes to the original function have been highlighted. Note that the internal field name for the “Title” field is “JobTitle” and that is what we are using to set the Title. Now if we run this modified script we should see the Title field updated:</p>

<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTMLa21bc70" border="0" alt="SNAGHTMLa21bc70" src="http://blog.falchionconsulting.com/wp-content/uploads/2011/12/SNAGHTMLa21bc70.png" width="608" height="207" /></p>

<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTMLa236af7" border="0" alt="SNAGHTMLa236af7" src="http://blog.falchionconsulting.com/wp-content/uploads/2011/12/SNAGHTMLa236af7.png" width="800" height="239" /></p>

<p>Okay, so what about the other fields (Department, Mobile Number, etc.)? You can see what fields are available to edit by running the following:</p>

<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTMLa265249" border="0" alt="SNAGHTMLa265249" src="http://blog.falchionconsulting.com/wp-content/uploads/2011/12/SNAGHTMLa265249.png" width="899" height="286" /></p>

<p>In the preceding example I’m grabbing a specific item (in this case the item corresponding to my user) so that I can see the internal field names in context with the data stored by the field – this helps to make sure that I grab the correct field name (i.e., “JobTitle” vs. “Title”). Now you can just add additional fields to update right before the call to SystemUpdate() – simply follow the pattern established for the title field.</p>

<p>So, add this guy to your script library and you’ll be good to go next time someone changes their name, email, or job title.</p>

<p>-Gary</p>]]></content:encoded>
			<wfw:commentRss>http://blog.falchionconsulting.com/index.php/2011/12/updating-sharepoint-2010-user-information/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		<feedburner:origLink>http://blog.falchionconsulting.com/index.php/2011/12/updating-sharepoint-2010-user-information/</feedburner:origLink></item>
		<item>
		<title>SharePoint Saturday Denver 2011 Slide Decks</title>
		<link>http://feedproxy.google.com/~r/AutomatingSharePoint/~3/mtYKUKtuswc/</link>
		<comments>http://blog.falchionconsulting.com/index.php/2011/11/sharepoint-saturday-denver-2011-slide-decks/#comments</comments>
		<pubDate>Sat, 19 Nov 2011 17:02:16 +0000</pubDate>
		<dc:creator>Gary Lapointe</dc:creator>
				<category><![CDATA[Speaking]]></category>
		<category><![CDATA[SharePoint Saturday]]></category>

		<guid isPermaLink="false">http://blog.falchionconsulting.com/index.php/2011/11/sharepoint-saturday-denver-2011-slide-decks/</guid>
		<description><![CDATA[Last weekend I had a great time at SharePoint Friday/Saturday Denver 2011 – all the folks who helped organize the event did a fantastic job (and I have to say, it was nice this year not being one of the organizers as I was able to just enjoy the event for once which makes me [...]]]></description>
			<content:encoded><![CDATA[<p>Last weekend I had a great time at SharePoint Friday/Saturday Denver 2011 – all the folks who helped organize the event did a fantastic job (and I have to say, it was nice this year not being one of the organizers as I was able to just enjoy the event for once which makes me appreciate their efforts even more). So, at the event I presented two talks, one on PowerShell (of course) and the other was the presentation I gave at the SharePoint Conference in Anaheim last month. The PowerShell talk was a new talk that I’d never done before and it was basically just a bunch of random tips that I’ve found useful over the years. My apologies to those who attended my sessions last weekend for not making these available sooner but I figure better late than never. Anyways, here’s the links to the decks – enjoy!</p>  <ul>   <li><a onclick="javascript:urchinTracker(&#39;/Presentations/SPSDenver/SharePoint2010PowerShellTipsTricksAndRandomGoodness.pptx&#39;);" href="http://blog.falchionconsulting.com/blog/Presentations/SPSDenver/SharePoint2010PowerShellTipsTricksAndRandomGoodness.pptx">SharePoint 2010 &amp; PowerShell: Tips, Tricks, and Random Goodness</a></li>    <li><a onclick="javascript:urchinTracker(&#39;/Presentations/SPSDenver/TaxonomyBasedContentTargetingforaSharePointInternetSite.pptx&#39;);" href="http://blog.falchionconsulting.com/blog/Presentations/SPSDenver/TaxonomyBasedContentTargetingforaSharePointInternetSite.pptx">Taxonomy Based Content Targeting for a SharePoint Internet Site</a></li> </ul>]]></content:encoded>
			<wfw:commentRss>http://blog.falchionconsulting.com/index.php/2011/11/sharepoint-saturday-denver-2011-slide-decks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.falchionconsulting.com/index.php/2011/11/sharepoint-saturday-denver-2011-slide-decks/</feedburner:origLink></item>
		<item>
		<title>Resetting SharePoint 2010 Themes – Part 2, the Reset-SPTheme cmdlet</title>
		<link>http://feedproxy.google.com/~r/AutomatingSharePoint/~3/KYnWsEOdJbo/</link>
		<comments>http://blog.falchionconsulting.com/index.php/2011/08/resetting-sharepoint-2010-themes-part-2-the-reset-sptheme-cmdlet/#comments</comments>
		<pubDate>Sat, 20 Aug 2011 23:18:03 +0000</pubDate>
		<dc:creator>Gary Lapointe</dc:creator>
				<category><![CDATA[PowerShell Cmdlets]]></category>
		<category><![CDATA[SharePoint 2010]]></category>
		<category><![CDATA[Cmdlets]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SharePoint Foundation 2010]]></category>
		<category><![CDATA[SharePoint Server 2010]]></category>
		<category><![CDATA[Themes]]></category>

		<guid isPermaLink="false">http://blog.falchionconsulting.com/index.php/2011/08/resetting-sharepoint-2010-themes-part-2-the-reset-sptheme-cmdlet/</guid>
		<description><![CDATA[Yesterday I threw up a quick post showing how to reset a SharePoint 2010 theme using a reasonably simple Windows PowerShell script. In that post I promised that I’d convert the script to a cmdlet and make it part of my downloadable extensions. Well, as promised I’ve updated my extensions so that they now include [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I threw up a quick <a href="http://blog.falchionconsulting.com/index.php/2011/08/resetting-sharepoint-2010-themes/" target="_blank">post showing how to reset a SharePoint 2010 theme</a> using a reasonably simple Windows PowerShell script. In that post I promised that I’d convert the script to a cmdlet and make it part of my downloadable extensions. Well, as promised I’ve updated my extensions so that they now include a <font face="Courier New"><strong>Reset-SPTheme</strong></font> cmdlet. I added on minor enhancement over the previously shown script in that I allow you to pass in either an <font face="Courier New">SPSite</font> or an <font face="Courier New">SPWeb</font> object and by default it will not force all child webs to inherit from the relevant <font face="Courier New">SPWeb</font> object. This way, if you have a child Site with it’s own theme it won’t wipe out that theme. If you have multiple Sites with a custom theme setting within a Site Collection then you’ll want to provide the -Site parameter and pass in an <font face="Courier New">SPSite</font> reference – this will result in all Sites with custom themes within the Site Collection to be reset. If you only wish to reset a single Site then use the -Web parameter and pass in a <font face="Courier New">SPWeb</font> reference.</p>  <p>Here’s the full help for the <font face="Courier New"><strong>Reset-SPTheme </strong></font>cmdlet:</p>  <div style="background-color: black; width: 100%; height: 400px; color: white; overflow: auto">   <p><font face="Courier New">NAME        <br />&#160;&#160;&#160; Reset-SPTheme</font></p>    <p><font face="Courier New">SYNOPSIS        <br />&#160;&#160;&#160; Resets a theme by applying all user specified theme configuration settings to the original source files. This is particularly helpful when the original source files have changed to a Feature upgrade.</font></p>    <p><font face="Courier New">SYNTAX        <br />&#160;&#160;&#160; Reset-SPTheme [-Web] &lt;SPWebPipeBind&gt; [-SetSubWebsToInherit &lt;SwitchParameter&gt;] [-AssignmentCollection &lt;SPAssignmentCollection&gt;] [&lt;CommonParameters&gt;]</font></p>    <p><font face="Courier New">&#160;&#160;&#160; Reset-SPTheme [-Site] &lt;SPSitePipeBind&gt; [-SetSubWebsToInherit &lt;SwitchParameter&gt;] [-AssignmentCollection &lt;SPAssignmentCollection&gt;] [&lt;CommonParameters&gt;]</font></p>    <p><font face="Courier New">DESCRIPTION        <br />&#160;&#160;&#160; Resets a theme by applying all user specified theme configuration settings to the original source files. This is particularly helpful when the original source files have changed to a Feature upgrade.</font></p>    <p><font face="Courier New">&#160;&#160;&#160; Copyright 2011 Falchion Consulting, LLC        <br />&#160;&#160;&#160; &gt; For more information on this cmdlet and others:         <br />&#160;&#160;&#160; &gt; </font><font face="Courier New">http://blog.falchionconsulting.com/</font>       <br /><font face="Courier New">&#160;&#160;&#160; &gt; Use of this cmdlet is at your own risk.        <br />&#160;&#160;&#160; &gt; Gary Lapointe assumes no liability.</font></p>    <p><font face="Courier New">PARAMETERS        <br />&#160;&#160;&#160; -Web &lt;SPWebPipeBind&gt;         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Specifies the URL or GUID of the Web containing the theme to reset.</font></p>    <p><font face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; The type must be a valid GUID, in the form 12345678-90ab-cdef-1234-567890bcdefgh; a valid name of Microsoft SharePoint Foundation 2010 Web site (for example, MySPSite1); or an instance of a valid SPWeb object.</font></p>    <p><font face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; true        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; true (ByValue, ByPropertyName)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false</font></p>    <p><font face="Courier New">&#160;&#160;&#160; -Site &lt;SPSitePipeBind&gt;        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; The site containing the theme to reset.</font></p>    <p><font face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; The type must be a valid GUID, in the form 12345678-90ab-cdef-1234-567890bcdefgh; a valid URL, in the form </font><font face="Courier New">http://server_name;</font><font face="Courier New"> or an instance of a valid SPSite object.</font></p>    <p><font face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; true        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; true (ByValue, ByPropertyName)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false</font></p>    <p><font face="Courier New">&#160;&#160;&#160; -SetSubWebsToInherit [&lt;SwitchParameter&gt;]        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; If specified, all child webs will be reset to inherit the theme of the specified web or root web.</font></p>    <p><font face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; false        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; named         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; false         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false</font></p>    <p><font face="Courier New">&#160;&#160;&#160; -AssignmentCollection [&lt;SPAssignmentCollection&gt;]        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Manages objects for the purpose of proper disposal. Use of objects, such as SPWeb or SPSite, can use large amounts of memory and use of these objects in Windows PowerShell scripts requires proper memory management. Using the SPAssignment object, you can assign objects to a variable and dispose of the objects after they are needed to free up memory. When SPWeb, SPSite, or SPSiteAdministration objects are used, the objects are automatically disposed of if an assignment collection or the Global parameter is not used.</font></p>    <p><font face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; When the Global parameter is used, all objects are contained in the global store. If objects are not immediately used, or disposed of by using the Stop-SPAssignment command, an out-of-memory scenario can occur.</font></p>    <p><font face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; Required?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; false        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Position?&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; named         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Default value         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept pipeline input?&#160;&#160;&#160;&#160;&#160;&#160; true (ByValue)         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Accept wildcard characters?&#160; false</font></p>    <p><font face="Courier New">&#160;&#160;&#160; &lt;CommonParameters&gt;        <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; This cmdlet supports the common parameters: Verbose, Debug,         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ErrorAction, ErrorVariable, WarningAction, WarningVariable,         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; OutBuffer and OutVariable. For more information, type,         <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &quot;get-help about_commonparameters&quot;.</font></p>    <p><font face="Courier New">INPUTS</font></p>    <p><font face="Courier New">OUTPUTS</font></p>    <p><font face="Courier New">NOTES</font></p>    <p><font face="Courier New">&#160;&#160;&#160;&#160;&#160;&#160;&#160; For more information, type &quot;Get-Help Reset-SPTheme -detailed&quot;. For technical information, type &quot;Get-Help Reset-SPTheme -full&quot;.</font></p>    <p><font face="Courier New">&#160;&#160;&#160; ------------------EXAMPLE 1-----------------------</font></p>    <p><font face="Courier New">&#160;&#160;&#160; PS C:\&gt; Get-SPSite </font><font face="Courier New">http://server_name</font><font face="Courier New"> | Reset-SPTheme -SetSubWebsToInherit</font></p>    <p><font face="Courier New">&#160;&#160;&#160; This example resets the theme for the site collection </font><font face="Courier New">http://server_name</font><font face="Courier New"> and resets all child webs to inherit from the root web.</font></p>    <p><font face="Courier New">&#160;&#160;&#160; ------------------EXAMPLE 2-----------------------</font></p>    <p><font face="Courier New">&#160;&#160;&#160; PS C:\&gt; Get-SPWeb </font><font face="Courier New">http://server_name/sub-web</font><font face="Courier New"> | Reset-SPTheme</font></p>    <p><font face="Courier New">&#160;&#160;&#160; This example resets the theme for the web </font><font face="Courier New">http://server_name/sub-web</font><font face="Courier New">.</font></p>    <p><font face="Courier New">RELATED LINKS        <br />&#160;&#160;&#160; Get-SPWeb         <br />&#160;&#160;&#160; Get-SPSite</font> </p> </div>  <p>&#160;</p>  <p>In the following example I’m resetting the theme(s) for an entire Site Collection. If one any child Sites within the Site Collection have a custom theme then they’ll be updated, not just the root (inheritance will not be changed):</p>  <p><font face="Courier New">PS C:\&gt; Reset-SPTheme -Site http://example.com</font></p>  <p>In this next example I’m resetting all child Sites to inherit whatever theme has been specified for the root Site and I’m updating the root Site’s theme with changes to the source files:</p>  <p><font face="Courier New">PS C:\&gt; Reset-SPTheme -Site http://example.com -SetSubWebsToInherit</font></p>  <p>For this last example I’m resetting the theme of a specific sub-Site:</p>  <p><font face="Courier New">PS C:\&gt; Reset-SPTheme -Web http://example.com</font>    <br /></p>  <p>As you can see, this is pretty easy to use and, if you’re deploying your branding via Features and you have theme support then a cmdlet like this can be quite critical when you need to push out updates to that brand.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.falchionconsulting.com/index.php/2011/08/resetting-sharepoint-2010-themes-part-2-the-reset-sptheme-cmdlet/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://blog.falchionconsulting.com/index.php/2011/08/resetting-sharepoint-2010-themes-part-2-the-reset-sptheme-cmdlet/</feedburner:origLink></item>
		<item>
		<title>Resetting SharePoint 2010 Themes</title>
		<link>http://feedproxy.google.com/~r/AutomatingSharePoint/~3/U1Z0GDn0uBY/</link>
		<comments>http://blog.falchionconsulting.com/index.php/2011/08/resetting-sharepoint-2010-themes/#comments</comments>
		<pubDate>Sat, 20 Aug 2011 04:58:14 +0000</pubDate>
		<dc:creator>Gary Lapointe</dc:creator>
				<category><![CDATA[SharePoint 2010]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SharePoint Foundation 2010]]></category>
		<category><![CDATA[SharePoint Server 2010]]></category>
		<category><![CDATA[Themes]]></category>

		<guid isPermaLink="false">http://blog.falchionconsulting.com/index.php/2011/08/resetting-sharepoint-2010-themes/</guid>
		<description><![CDATA[UPDATE 8/20/2011: I’ve reworked this script and included it as part of my SharePoint 2010 cmdlet downloads. See “Resetting SharePoint 2010 Themes – Part 2, the Reset-SPTheme cmdlet” for details. One of my current clients is a local school district here in Denver and we (Aptillon) have recently helped them release a new public facing [...]]]></description>
			<content:encoded><![CDATA[<p><font color="#ff0000"><strong>UPDATE 8/20/2011</strong>: I’ve reworked this script and included it as part of my SharePoint 2010 cmdlet downloads. See “<a title="Resetting SharePoint 2010 Themes – Part 2, the Reset-SPTheme cmdlet" href="http://blog.falchionconsulting.com/index.php/2011/08/resetting-sharepoint-2010-themes-part-2-the-reset-sptheme-cmdlet/">Resetting SharePoint 2010 Themes – Part 2, the Reset-SPTheme cmdlet</a>” for details.</font></p>  <p>One of my current clients is a local school district here in Denver and we (Aptillon) have recently helped them release a new public facing site for the main district office as well as all the schools in the district. The district has chosen a somewhat fixed brand which has had full theming support added so that the individual schools can adjust the color scheme to match the school’s colors. The master page, page layouts, CSS files, and associated images were all deployed to the Farm using various Solution Packages (WSPs). This allows us to make corrections/additions to the brand related files and quickly deploy them to the Farm, thereby updating the district and school sites quite easily. The problem, however, is that the way theming works within SharePoint 2010 is that it makes a copy of all the CSS and image files and stores them in the <strong>/_catalogs/theme/Themed/<em>{THEMEID}</em></strong> folder, as shown in the following figure:</p>  <p><a href="http://blog.falchionconsulting.com/wp-content/Images/db503824bc94_12CE6/ThemedFolder.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ThemedFolder" border="0" alt="ThemedFolder" src="http://blog.falchionconsulting.com/wp-content/Images/db503824bc94_12CE6/ThemedFolder_thumb.png" width="330" height="453" /></a></p>  <p>Whenever you apply a theme it will copy all the necessary CSS and image files to a new folder in the <em>Themed</em> folder. This means that the site is no longer basing its look and feel off of the Feature deployed files. So if a school has gone in and customized their site to use themes then any updates that we push out to the style sheets and images will be ignored. So I needed a way to effectively “reset” the applied theme after we push out an update to our branding solution. By reset I mean preserve the various color and font settings but re-apply them against the Feature deployed files.</p>  <p>I did some digging with my favorite tool, Reflector, and found that the out of the box theme settings page just uses the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.thmxtheme.aspx" target="_blank">Microsoft.SharePoint.Utilities.ThmxTheme</a><font face="Courier New"></font> class to manipulate the themes. So, after a little experimenting I ended up with some code which will regenerate the current theme using all the source files and the user provided theme settings:</p>  <blockquote>   <pre><span style="color: #008000">#</span><span style="color: #008000">NOTE: Run in a seperate console instance each time otherwise the changes won't get applied</span><span style="color: #008000">
</span><span style="color: #0000ff">function</span><span style="color: #000000"> </span><span style="color: #5f9ea0">Reset-SPTheme</span><span style="color: #000000">([</span><span style="color: #008080">Microsoft.SharePoint.PowerShell.SPSitePipeBind</span><span style="color: #000000">]</span><span style="color: #800080">$spSite</span><span style="color: #000000">) {
    </span><span style="color: #800080">$site</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$spSite</span><span style="color: #000000">.Read()
    </span><span style="color: #0000ff">try</span><span style="color: #000000"> {
        </span><span style="color: #008000">#</span><span style="color: #008000"> Store some variables for later use</span><span style="color: #008000">
</span><span style="color: #000000">        </span><span style="color: #800080">$tempFolderName</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">TEMP</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #800080">$themedFolderName</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">$($site.ServerRelativeUrl)/_catalogs/theme/Themed</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #800080">$themesUrlForWeb</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> [</span><span style="color: #008080">Microsoft.SharePoint.Utilities.ThmxTheme</span><span style="color: #000000">]::</span><span style="color: #8b4513">GetThemeUrlForWeb</span><span style="color: #000000">(</span><span style="color: #800080">$site</span><span style="color: #000000">.RootWeb)
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Old Theme URL: $themesUrlForWeb</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        
        </span><span style="color: #008000">#</span><span style="color: #008000"> Open the existing theme</span><span style="color: #008000">
</span><span style="color: #000000">        </span><span style="color: #800080">$webThmxTheme</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> [</span><span style="color: #008080">Microsoft.SharePoint.Utilities.ThmxTheme</span><span style="color: #000000">]::</span><span style="color: #8b4513">Open</span><span style="color: #000000">(</span><span style="color: #800080">$site</span><span style="color: #000000">, </span><span style="color: #800080">$themesUrlForWeb</span><span style="color: #000000">)
        
        </span><span style="color: #008000">#</span><span style="color: #008000"> Generate a new theme using the settings defined for the existing theme</span><span style="color: #008000">
</span><span style="color: #000000">        </span><span style="color: #008000">#</span><span style="color: #008000"> (this will generate a temporary theme folder that we'll need to delete)</span><span style="color: #008000">
</span><span style="color: #000000">        </span><span style="color: #800080">$webThmxTheme</span><span style="color: #000000">.GenerateThemedStyles(</span><span style="color: #800080">$true</span><span style="color: #000000">, </span><span style="color: #800080">$site</span><span style="color: #000000">.RootWeb, </span><span style="color: #800080">$tempFolderName</span><span style="color: #000000">)
        
        </span><span style="color: #008000">#</span><span style="color: #008000"> Apply the newly generated theme to the root web</span><span style="color: #008000">
</span><span style="color: #000000">        [</span><span style="color: #008080">Microsoft.SharePoint.Utilities.ThmxTheme</span><span style="color: #000000">]::</span><span style="color: #8b4513">SetThemeUrlForWeb</span><span style="color: #000000">(</span><span style="color: #800080">$site</span><span style="color: #000000">.RootWeb, </span><span style="color: #800000">&quot;</span><span style="color: #800000">$themedFolderName/$tempFolderName/theme.thmx</span><span style="color: #800000">&quot;</span><span style="color: #000000">, </span><span style="color: #800080">$true</span><span style="color: #000000">)
        
        </span><span style="color: #008000">#</span><span style="color: #008000"> Delete the TEMP folder created earlier</span><span style="color: #008000">
</span><span style="color: #000000">        </span><span style="color: #800080">$site</span><span style="color: #000000">.RootWeb.GetFolder(</span><span style="color: #800000">&quot;</span><span style="color: #800000">$themedFolderName/$tempFolderName</span><span style="color: #800000">&quot;</span><span style="color: #000000">).Delete()
        
        </span><span style="color: #008000">#</span><span style="color: #008000"> Reset the theme URL just in case it has changed (sometimes it will)</span><span style="color: #008000">
</span><span style="color: #000000">        </span><span style="color: #800080">$site</span><span style="color: #000000">.Dispose()
        </span><span style="color: #800080">$site</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$spSite</span><span style="color: #000000">.Read()
        </span><span style="color: #800080">$themesUrlForWeb</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> [</span><span style="color: #008080">Microsoft.SharePoint.Utilities.ThmxTheme</span><span style="color: #000000">]::</span><span style="color: #8b4513">GetThemeUrlForWeb</span><span style="color: #000000">(</span><span style="color: #800080">$site</span><span style="color: #000000">.RootWeb)
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">New Theme URL: $themesUrlForWeb</span><span style="color: #800000">&quot;</span><span style="color: #000000">

        </span><span style="color: #008000">#</span><span style="color: #008000"> Set all child webs to inherit.</span><span style="color: #008000">
</span><span style="color: #000000">        </span><span style="color: #0000ff">if</span><span style="color: #000000"> ([</span><span style="color: #008080">Microsoft.SharePoint.Publishing.PublishingWeb</span><span style="color: #000000">]::</span><span style="color: #8b4513">IsPublishingWeb</span><span style="color: #000000">(</span><span style="color: #800080">$site</span><span style="color: #000000">.RootWeb)) {
            </span><span style="color: #800080">$pubWeb</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> [</span><span style="color: #008080">Microsoft.SharePoint.Publishing.PublishingWeb</span><span style="color: #000000">]::</span><span style="color: #8b4513">GetPublishingWeb</span><span style="color: #000000">(</span><span style="color: #800080">$site</span><span style="color: #000000">.RootWeb)
            </span><span style="color: #800080">$pubWeb</span><span style="color: #000000">.ThemedCssFolderUrl.SetValue(</span><span style="color: #800080">$pubWeb</span><span style="color: #000000">.Web.ThemedCssFolderUrl, </span><span style="color: #800080">$true</span><span style="color: #000000">)
        } </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
            </span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (</span><span style="color: #800080">$web</span><span style="color: #000000"> </span><span style="color: #0000ff">in</span><span style="color: #000000"> </span><span style="color: #800080">$site</span><span style="color: #000000">.AllWebs) {
                </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$web</span><span style="color: #000000">.isRootWeb) { </span><span style="color: #0000ff">continue</span><span style="color: #000000"> }
                </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Setting theme for $($web.ServerRelativeUrl)...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
                </span><span style="color: #0000ff">try</span><span style="color: #000000"> {
                    [</span><span style="color: #008080">Microsoft.SharePoint.Utilities.ThmxTheme</span><span style="color: #000000">]::</span><span style="color: #8b4513">SetThemeUrlForWeb</span><span style="color: #000000">(</span><span style="color: #800080">$web</span><span style="color: #000000">, </span><span style="color: #800080">$themesUrlForWeb</span><span style="color: #000000">)
                } </span><span style="color: #0000ff">finally</span><span style="color: #000000"> {
                    </span><span style="color: #800080">$web</span><span style="color: #000000">.Dispose()
                }
            }   
        }
    } </span><span style="color: #0000ff">finally</span><span style="color: #000000"> {
        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$site</span><span style="color: #000000"> </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) { </span><span style="color: #800080">$site</span><span style="color: #000000">.Dispose() }
    }
}
</span></pre>
</blockquote>

<p>I saved this to a file named <font face="Courier New"><strong>Reset-SPTheme</strong></font> so I can then call the function like so:</p>

<blockquote>
  <pre><span style="color: #000000">. c:\Scripts\Reset-SPTheme.ps1
</span><span style="color: #5f9ea0">Reset-SPTheme</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">http://example.com/</span><span style="color: #800000">&quot;</span></pre>
</blockquote>

<p>One odd thing I found, however, is that every time I run this it must be run in a new console instance; otherwise the changes are not picked up (this is basically a combination of a threading and caching issue within the code when executed from a PowerShell context). So remember, start a new PowerShell console every time you need to run this script (yeah, I wasted a couple of hours banging my head against the wall trying to figure that little nugget out).</p>

<p><strike>BTW: I intend to add this to my cmdlet extensions as I believe it will be something I’ll need often so look for an updated build to come out this weekend.</strike></p>]]></content:encoded>
			<wfw:commentRss>http://blog.falchionconsulting.com/index.php/2011/08/resetting-sharepoint-2010-themes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blog.falchionconsulting.com/index.php/2011/08/resetting-sharepoint-2010-themes/</feedburner:origLink></item>
		<item>
		<title>SharePoint 2010 SP1 Public API Changes</title>
		<link>http://feedproxy.google.com/~r/AutomatingSharePoint/~3/JVZ-XBj9OGo/</link>
		<comments>http://blog.falchionconsulting.com/index.php/2011/07/sharepoint-2010-sp1-public-api-changes/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 03:15:35 +0000</pubDate>
		<dc:creator>Gary Lapointe</dc:creator>
				<category><![CDATA[SharePoint 2010]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Service Pack 1]]></category>
		<category><![CDATA[SharePoint Foundation 2010]]></category>
		<category><![CDATA[SharePoint Server 2010]]></category>

		<guid isPermaLink="false">http://blog.falchionconsulting.com/index.php/2011/07/sharepoint-2010-sp1-public-api-changes/</guid>
		<description><![CDATA[.post ul li { background-position: left top; background-repeat: no-repeat; padding-left: 20px; list-style-type: none; list-style-position: outside; } ul.assemblies li { background-image: url(http://blog.falchionconsulting.com/blog/Icons/Icon_Assembly.png); } ul.properties li { background-image: url(http://blog.falchionconsulting.com/blog/Icons/Icon_Property.png); } ul.classes li { background-image: url(http://blog.falchionconsulting.com/blog/Icons/Icon_Class.png); } ul.interfaces li { background-image: url(http://blog.falchionconsulting.com/blog/Icons/Icon_Interface.png); } ul.enumvalues li { background-image: url(http://blog.falchionconsulting.com/blog/Icons/Icon_EnumValue.png); } ul.enumtypes li { background-image: url(http://blog.falchionconsulting.com/blog/Icons/Icon_EnumType.png); } ul.constants li { [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
.post ul li {
	background-position: left top;
	background-repeat: no-repeat;
	padding-left: 20px;
	list-style-type: none;
	list-style-position: outside;
}

ul.assemblies li {
	background-image: url(http://blog.falchionconsulting.com/blog/Icons/Icon_Assembly.png);
}

ul.properties li 
{
	background-image: url(http://blog.falchionconsulting.com/blog/Icons/Icon_Property.png);
}
ul.classes li {
	background-image: url(http://blog.falchionconsulting.com/blog/Icons/Icon_Class.png);
}
ul.interfaces li {
	background-image: url(http://blog.falchionconsulting.com/blog/Icons/Icon_Interface.png);
}
ul.enumvalues li {
	background-image: url(http://blog.falchionconsulting.com/blog/Icons/Icon_EnumValue.png);
}
ul.enumtypes li {
	background-image: url(http://blog.falchionconsulting.com/blog/Icons/Icon_EnumType.png);
}
ul.constants li {
	background-image: url(http://blog.falchionconsulting.com/blog/Icons/Icon_Constant.png);
}
ul.methods li {
	background-image: url(http://blog.falchionconsulting.com/blog/Icons/Icon_Method.png);
}
li.label {
	background-image: none !important;
	list-style-type: circle;
	padding-left: 0px;
}</style>  <p>I recently published a post detailing the <a href="http://blog.falchionconsulting.com/index.php/2011/06/sharepoint-server-2010-service-pack-1-powershell-changes/" target="_blank">SharePoint 2010 SP1 PowerShell changes</a> and, in that post, I mentioned that I was probably going to detail the API changes. Well, here they are. Note that the list below is not a comprehensive one in that I’m not showing every assembly (I do have the changes for every assembly but frankly I just got tired of translating the results into a readable format so I kept it to the more prominent assemblies (or at least the ones that I just happened to have done at the time)). In reviewing the list you see that there’s honestly not a whole lot of noteworthy changes, but that’s okay as part of my reasoning for doing this was to discover whether there were any (don’t get me wrong, there are some, in fact, for me there’s 1 very big one that made this whole exercise worth it – I’ll let you figure out which one that is). If you find any I missed please add a comment so that others can see it as well.</p>  <ul class="assemblies">   <li><strong>Microsoft.SharePoint.dll</strong>       <ul class="classes">       <li><em>Microsoft.SharePoint.SPRecycleBinItemType</em>           <ul>           <li class="label">New enum value:              <ul class="enumvalues">               <li><em>Web</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.SPWeb</em>           <ul>           <li class="label">New method:              <ul class="methods">               <li><em>public void Recycle()</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Strings</em>           <ul>           <li class="label">New constants:              <ul class="constants">               <li><em>public const string CannotRecycleRootWeb</em> </li>                <li><em>public const string HealthRule_Explanation_BcsShimsAreEnabled</em> </li>                <li><em>public const string HealthRule_Remedy_BcsShimsAreEnabled</em> </li>                <li><em>public const string RecycleBinWebMissingContainerError</em> </li>                <li><em>public const string SPStorageMetricsProcessingJobDescription </em></li>                <li><em>public const string SPUsageUserCodeRequestsDescription </em></li>                <li><em>public const string SPUsageUserCodeRequestsMonitoredDataDescription</em> </li>                <li><em>public const string SiteAlreadyExists</em> </li>                <li><em>public const string StorageMetricsDBObjectsNotFound</em> </li>                <li><em>public const string StorageMetricsFreshnessWarning</em> </li>                <li><em>public const string StorageMetricsNotAvailable</em> </li>                <li><em>public const string TimerJobTitleStorageMetricsProcessing</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.SPAce&lt;T&gt;</em>           <ul>           <li class="label">New properties:              <ul class="properties">               <li><em>public Byte[] BinaryId() { get; }</em> </li>                <li><em>public Microsoft.SharePoint.Administration.SPIdentifierType BinaryIdType() { get; }</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.SPAcl&lt;T&gt;</em>           <ul>           <li class="label">New method:              <ul class="methods">               <li><em>public SPAce&lt;T&gt; Add(string principalName, string displayName, SPIdentifierType identifierType, byte[] identifier, T grantRightsMask, T denyRightsMask)</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.SPContentDatabase</em>           <ul>           <li class="label">New methods:              <ul class="methods">               <li><em>public Microsoft.SharePoint.Administration.SPDeletedSite GetDeletedSite(System.Guid id)</em> </li>                <li><em>public void Move(SPContentDatabase destinationDb, List&lt;SPSite&gt; sitesToMove, Dictionary&lt;string, string&gt; rbsProviderMap, out Dictionary&lt;SPSite, string&gt; failedSites)</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.SPContentDatabaseCollection</em>           <ul>           <li class="label">New method:              <ul class="methods">               <li><em>public SPContentDatabase Add(string strDatabaseServer, string strDatabaseName, string strDatabaseUsername, string strDatabasePassword, int warningSiteCount, int maximumSiteCount, int status, bool flushChangeLog, bool changeSyncKnowledge)</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.SPDatabase</em>           <ul>           <li class="label">New method:              <ul class="methods">               <li><em>public void ChangeDatabaseInstance(string databaseServiceInstance)</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.SPIncomingEmailService</em>           <ul>           <li class="label">New property:              <ul class="properties">               <li><em>public int RetryDeliveryInterval { get; set; }</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.SPPolicy</em>           <ul>           <li class="label">New method:              <ul class="methods">               <li><em>protected Void OnDeserialization()</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.SPSiteLookupProvider</em>           <ul>           <li class="label">Changed method (<font color="#ff0000">breaking change!</font>)               <ul class="methods">               <li><em>public Void RenameHostHeaderSite(Guid siteId, string newHostHeader)</em> =&gt; <em>public Void RenameHostHeaderSite(Guid siteId, Uri newHostHeaderSiteUri)</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.SPUsageApplication</em>           <ul>           <li class="label">New property:              <ul class="properties">               <li><em>public int UsageInsertionTimeOut { get; set; }</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.SPUserCodeExecutionTier</em>           <ul>           <li class="label">New property:              <ul class="properties">               <li><em>public int PriorityPerProcess { get; set; }</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.SPWebApplication</em>           <ul>           <li class="label">New properties:              <ul class="properties">               <li><em>public int StorageMetricsProcessingDuration { get; set; }</em> </li>                <li><em>public uint MaxDiscussionBoardItemsForSiteDataFolderQuery { get; set; }</em> </li>                <li><em>public uint? UserDefinedWorkflowMaximumComplexity { get; set; }</em> </li>             </ul>           </li>            <li class="label">New methods:              <ul class="methods">               <li><em>public SPDeletedSiteCollection GetDeletedSites()</em> </li>                <li><em>public SPDeletedSiteCollection GetDeletedSites(SPDeletedSiteQuery query)</em> </li>                <li><em>public SPDeletedSiteCollection GetDeletedSites(Guid siteId)</em> </li>                <li><em>public SPDeletedSiteCollection GetDeletedSites(string sitePath)</em> </li>                <li><em>public void MigrateUsers(IMigrateUserCallback callback)</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.SPWebService</em>           <ul>           <li class="label">New properties:              <ul class="properties">               <li><em>public int ImagingDownloadSizeLimit { get; set; }</em> </li>                <li><em>public bool EnableHostHeaderSiteBasedSchemeSelection { get; set; }</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.Claims.SPActiveDirectoryClaimProvider</em>           <ul>           <li class="label">New method:              <ul class="methods">               <li><em>protected override void FillDefaultLocalizedDisplayName(CultureInfo culture, out string localizedName)</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.Claims.SPAllUserClaimProvider</em>           <ul>           <li class="label">New method:              <ul class="methods">               <li><em>protected override void FillDefaultLocalizedDisplayName(CultureInfo culture, out string localizedName)</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.Claims.SPClaimHierarchyProvider</em>           <ul>           <li class="label">New methods:              <ul class="methods">               <li><em>protected override void FillDefaultLocalizedDisplayName(CultureInfo culture, out string localizedName)</em> </li>                <li><em>public string GetLocalizedDisplayName()</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.Claims.SPClaimProvider</em>           <ul>           <li class="label">New property:              <ul class="properties">               <li><em>public virtual bool SupportsUserKey { get; }</em> </li>             </ul>           </li>            <li class="label">New methods:              <ul class="methods">               <li><em>protected override void FillDefaultLocalizedDisplayName(CultureInfo culture, out string localizedName)</em> </li>                <li><em>public string GetLocalizedDisplayName()</em> </li>                <li><em>public SPClaim UserKeyForEntity(SPClaim entity)</em> </li>                <li><em>public virtual string GetClaimTypeForUserKey()</em> </li>                <li><em>protected virtual SPClaim GetUserKeyForEntity(SPClaim entity)</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.Claims.SPClaimProviderDefinition</em>           <ul>           <li class="label">New property:              <ul class="properties">               <li><em>public bool IsVisible { get; set; }</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.Claims.SPClaimProviderOperationOptions</em>           <ul>           <li class="label">New enum value:              <ul class="enumvalues">               <li><em>OverrideVisibleFlag</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.Claims.SPFormsClaimProvider</em>           <ul>           <li class="label">New method:              <ul class="methods">               <li><em>protected override void FillDefaultLocalizedDisplayName(CultureInfo culture, out string localizedName)</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Administration.Claims.SPSystemClaimProvider</em>           <ul>           <li class="label">New method:              <ul class="methods">               <li><em>protected override void FillDefaultLocalizedDisplayName(CultureInfo culture, out string localizedName)</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.BusinessData.Administration.LobSystem</em>           <ul>           <li class="label">New static method:              <ul class="methods">               <li><em>public static LobSystem MergeXml(string xml, out string[] errors, PackageContents packageContents, AdministrationMetadataCatalog metadataCatalog, string settingId)</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.BusinessData.Administration.TypeDescriptor</em>           <ul>           <li class="label">New static method:              <ul class="methods">               <li><em>public static TypeDescriptor MergeXml(string xml, out string[] errors, PackageContents packageContents, Parameter parameter, TypeDescriptor parent, string settingId)</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.BusinessData.SharedService.BdcServiceApplicationProxy</em>           <ul>           <li class="label">New methods:              <ul class="methods">               <li><em>public bool IsSystemTypeEnabled(SystemType systemType)</em> </li>                <li><em>public void EnableSystemType(SystemType systemType, bool value)</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.JSGrid.GridSerializer</em>           <ul>           <li class="label">New method:              <ul class="methods">               <li><em>public void ApplyPostViewIncrementalInsertsAndDeletes(IEnumerable<change> changes, Func</em><object, Dictionary<string, object>> fnGetDefaultValuesForPostViewInserts)</object> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.JSGrid.HierarchyNode</em>           <ul>           <li class="label">New property:              <ul class="properties">               <li><em>public HierarchyNode Parent { get; set; }</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Utilities.SPUtility</em>           <ul>           <li class="label">New static method:              <ul class="methods">               <li><em>public static Stream ExecuteCellStorageBinaryRequest(SPFile spfile, Stream request, bool coalesce, ref Guid partitionID, string userName, bool coauthVersioning, string etagMatching, bool fExpectNoFileExists, string contentChangeUnit, string clientFileID, string bypassSchemaID, long nLockType, string lockID, long nTimeout, bool createParentFolder, out string etagReturn, out bool allRequestSucceeded, out int coalesceHRESULT, out string coalesceErrorMessage, out bool containHotboxData, out bool haveOnlyDemotionChanges, ref int binaryReqCountQuota)</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.WebPartPages.ListFormWebPart</em>           <ul>           <li class="label">New method:              <ul class="methods">               <li><em>public bool ShouldSerializeTemplateName()</em> </li>             </ul>           </li>         </ul>       </li>        <li class="label">New classes:          <ul class="classes">           <li><em>Microsoft.SharePoint.Administration.SPDeletedSite</em> </li>            <li><em>Microsoft.SharePoint.Administration.SPDeletedSiteCollection</em> </li>            <li><em>Microsoft.SharePoint.Administration.SPDeletedSiteLookupInfo</em> </li>            <li><em>Microsoft.SharePoint.Administration.SPDeletedSiteQuery</em> </li>            <li><em>Microsoft.SharePoint.Administration.SPUsageUserCodeRequests</em> </li>            <li><em>Microsoft.SharePoint.Administration.SPUsageUserCodeRequestsEntry</em> </li>            <li><em>Microsoft.SharePoint.Administration.SPUsageUserCodeRequestsMonitoredData</em> </li>            <li><em>Microsoft.SharePoint.Administration.SPUsageUserCodeRequestsMonitoredDataEntry</em> </li>            <li><em>Microsoft.SharePoint.Administration.Health.SPHealthAnalysisRuleInstance</em> </li>            <li><em>Microsoft.SharePoint.WebControls.IEVersionMetaTag</em> </li>         </ul>       </li>        <li class="label">New enum types:          <ul class="enumtypes">           <li><em>Microsoft.SharePoint.Administration.SPIdentifierType</em> </li>         </ul>       </li>        <li class="label">New interfaces:          <ul class="interfaces">           <li><em>Microsoft.SharePoint.Administration.IMigrateUserCallback</em> </li>            <li><em>Microsoft.SharePoint.Administration.ISPSiteLookupProviderRecycleBin</em> </li>         </ul>       </li>     </ul>   </li>    <li><strong>Microsoft.SharePoint.Publishing.dll</strong>       <ul class="classes">       <li><em>Microsoft.SharePoint.Publishing.Internal.CodeBehind</em>           <ul>           <li class="label">New property:              <ul class="properties">               <li><em>protected bool IsCurrentUserSiteAdmin { get; }</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Publishing.WebControls.SpellCheckV4Action</em>           <ul>           <li class="label">New method:              <ul class="methods">               <li><em>protected bool ShouldRenderWithoutTabs()</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ConsoleAction</em>           <ul>           <li class="label">New method:              <ul class="methods">               <li><em>protected bool ShouldRenderWithoutTabs()</em> </li>             </ul>           </li>         </ul>       </li>     </ul>   </li>    <li><strong>Microsoft.SharePoint.Taxonomy.dll</strong>       <ul class="classes">       <li><em>Microsoft.SharePoint.Taxonomy.TermStore</em>           <ul>           <li class="label">New method:              <ul class="methods">               <li><em>public Group GetSiteCollectionGroup(SPSite currentSite)</em> </li>             </ul>           </li>         </ul>       </li>     </ul>   </li>    <li><strong>Microsoft.SharePoint.Portal.dll</strong>       <ul class="classes">       <li><em>Microsoft.Office.Server.UserProfiles.UserProfileService</em>           <ul>           <li class="label">New methods:              <ul class="methods">               <li><em>public void AddLeader(string accountName)</em> </li>                <li><em>public Leader[] GetLeaders()</em> </li>                <li><em>public void RemoveLeader(string accountName)</em> </li>             </ul>           </li>         </ul>       </li>     </ul>   </li>    <li><strong>Microsoft.Office.Server.UserProfiles.dll</strong>       <ul class="classes">       <li><em>Microsoft.Office.Server.SocialData.PluggableSocialSecurityTrimmerManager</em>           <ul>           <li class="label">New methods:              <ul class="methods">               <li><em>public static string[] GetUrlFoldersRequiringTrim(SPServiceContext serviceContext)</em> </li>                <li><em>public static string[] GetUrlFoldersToAlwaysAllow(SPServiceContext serviceContext)</em> </li>                <li><em>public static void SetTrimmerSettings(SPServiceContext serviceContext, bool enableTrimming)</em> </li>                <li><em>public static void SetTrimmerSettings(SPServiceContext serviceContext, string[] urlFoldersRequiringTrim, string[] urlFoldersToAlwaysAllow)</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.Office.Server.UserProfiles.BusinessDataCatalogConnection</em>           <ul>           <li class="label">New method:              <ul class="methods">               <li><em>public void Delete()</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.Office.Server.UserProfiles.ConnectionManager</em>           <ul>           <li class="label">New method:              <ul class="methods">               <li><em>public DirectoryServiceConnection AddActiveDirectoryConnection(ConnectionType type, string displayName, string server, bool useSSL, string accountDomain, string accountUsername, SecureString accountPassword, List&lt;DirectoryServiceNamingContext&gt; namingContexts, string spsClaimProviderTypeValue, string spsClaimProviderIdValue, string adClaimIDMapAttribute)</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.Office.Server.UserProfiles.UserProfileManager</em>           <ul>           <li class="label">New methods:              <ul class="methods">               <li><em>public void AddLeader(string accountName)</em> </li>                <li><em>public Leader[] GetLeaders()</em> </li>                <li><em>public void RemoveLeader(string accountName)</em> </li>             </ul>           </li>         </ul>       </li>        <li class="label">New classes:          <ul class="classes">           <li><em>Microsoft.Office.Server.UserProfiles.Leader</em> </li>         </ul>       </li>     </ul>   </li>    <li><strong>Microsoft.Office.Server.Search.dll</strong>       <ul class="classes">       <li><em>Microsoft.Office.Server.Search.Administration.CrawlTopologyState</em>           <ul>           <li class="label">New enum values:              <ul class="enumvalues">               <li><em>ActiveToBeRemoved</em> </li>                <li><em>DeactivatingToBeRemoved</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.Office.Server.Search.Administration.SearchServiceApplication</em>           <ul>           <li class="label">New property:              <ul class="properties">               <li><em>public uint CrawlLogCleanupIntervalInDays { get; set; }</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.Office.Server.Search.Administration.SearchServiceApplicationProxy</em>           <ul>           <li class="label">New property:              <ul class="proeprties">               <li><em>public LocationConfigurationCollection LocationConfigurations { get; }</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.Office.Server.Search.Query.QueryInfo</em>           <ul>           <li class="label">New property:              <ul class="properties">               <li><em>public string CorrelationId { get; set; }</em> </li>             </ul>           </li>         </ul>       </li>        <li><em>Microsoft.Office.Server.Search.Query.QueryManager</em>           <ul>           <li class="label">New method:              <ul class="methods">               <li><em>public System.Xml.XmlDocument GetResults()</em> </li>             </ul>           </li>         </ul>       </li>     </ul>   </li>    <li><strong>Microsoft.SharePoint.PowerShell.dll</strong>       <ul class="classes">       <li class="label">New classes:          <ul class="classes">           <li><em>Microsoft.SharePoint.PowerShell.SPDeletedSitePipeBind</em> </li>            <li><em>Microsoft.SharePoint.PowerShell.SPHealthAnalysisRuleInstancePipeBind</em> </li>         </ul>       </li>     </ul>   </li> </ul>]]></content:encoded>
			<wfw:commentRss>http://blog.falchionconsulting.com/index.php/2011/07/sharepoint-2010-sp1-public-api-changes/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://blog.falchionconsulting.com/index.php/2011/07/sharepoint-2010-sp1-public-api-changes/</feedburner:origLink></item>
		<item>
		<title>SharePoint Server 2010 Service Pack 1 PowerShell Changes</title>
		<link>http://feedproxy.google.com/~r/AutomatingSharePoint/~3/APjS6yfHs0U/</link>
		<comments>http://blog.falchionconsulting.com/index.php/2011/06/sharepoint-server-2010-service-pack-1-powershell-changes/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 04:55:24 +0000</pubDate>
		<dc:creator>Gary Lapointe</dc:creator>
				<category><![CDATA[SharePoint 2010]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Service Pack 1]]></category>
		<category><![CDATA[SharePoint Server 2010]]></category>
		<category><![CDATA[SP1]]></category>

		<guid isPermaLink="false">http://blog.falchionconsulting.com/index.php/2011/06/sharepoint-server-2010-service-pack-1-powershell-changes/</guid>
		<description><![CDATA[As most people know by now, Service Pack 1 for SharePoint 2010 was released to the public today. There’s already been a lot of hype over some of the new capabilities such as the site recycle bin and some folks have documented/demonstrated some of the new PowerShell cmdlets that are available to manage this new [...]]]></description>
			<content:encoded><![CDATA[<p>As most people know by now, <a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=26623" target="_blank">Service Pack 1 for SharePoint 2010</a> was released to the public today. There’s already been a lot of hype over some of the new capabilities such as the site recycle bin and some folks have documented/demonstrated some of the new PowerShell cmdlets that are available to manage this new feature; but what about all the other new and changed PowerShell cmdlets – there’s a bunch! So, let’s take a look at what is new, and what has changed.</p>  <p>We’ll start with the new stuff – here’s a quick bulleted list of all the new cmdlets:</p>  <ul>   <li><font face="Courier New"><strong>Add-SPProfileLeader</strong></font> </li>    <li><font face="Courier New"><strong>Get-SPProfileLeader</strong></font> </li>    <li><font face="Courier New"><strong>Remove-SPProfileLeader</strong></font> </li>    <li><font face="Courier New"><strong>Remove-SPProfileSyncConnection</strong></font> </li>    <li><font face="Courier New"><strong>Add-SPProfileSyncConnection</strong></font> </li>    <li><font face="Courier New"><strong>Disable-SPHealthAnalysisRule</strong></font> </li>    <li><font face="Courier New"><strong>Enable-SPHealthAnalysisRule</strong></font> </li>    <li><font face="Courier New"><strong>Get-SPHealthAnalysisRule</strong></font> </li>    <li><font face="Courier New"><strong>Get-SPDeletedSite</strong></font> </li>    <li><font face="Courier New"><strong>Remove-SPDeletedSite</strong></font> </li>    <li><font face="Courier New"><strong>Restore-SPDeletedSite</strong></font> </li>    <li><font face="Courier New"><strong>Move-SPSocialComments</strong></font> </li> </ul>  <p>I haven’t had a chance to try any of these out but I think there’s some cool new functionality here beyond just the site recycle bin. There’s absolutely no documentation for any of these but some of them are fairly straightforward based on the names. For instance, the <font face="Courier New"><strong>Add-SPProfileSyncConnection</strong></font> cmdlet (and equivalent <font face="Courier New">Remove</font> cmdlet) are obviously for managing the synchronization connections for UPS. This was a big whole in RTM when it came to doing an end-to-end scripted installation as there was no practical way to add a synchronization connection using PowerShell. The health analysis rule cmdlets are also pretty obvious and, again, this goes a long way towards enabling administrators to script a deployment and enable or disable rules consistently across Farms.</p>  <p>I think the <font face="Courier New"><strong>Move-SPSocialComments</strong></font> also has a lot of potential; if it does what I’m guessing it does then this could potentially solve the issue where comments and tags are stored with the absolute URL of the item that has been tagged/commented on – I’m *guessing* that running this command will effectively retarget those items, which is great in situations in which you’ve moved a list or site.</p>  <p>As for the <font face="Courier New"><strong>*-SPProfileLeader</strong></font> cmdlets – I have no idea what those guys do so I’ll have to revisit them when I learn more. (The <strong><font face="Courier New">*-SPDeletedSite</font></strong> cmdlets have already been covered quite a bit by others so I’ll forgo any further discussion here).</p>  <p>Alright, so that’s the new stuff – what about the stuff that’s changed? Here’s a quick list with the changes:</p>  <ul>   <li><a href="http://technet.microsoft.com/en-us/library/ff607581.aspx" target="_blank"><strong><font face="Courier New">Mount-SPContentDatabase</font></strong></a>       <ul>       <li>New Switch Parameter: <font face="Courier New"><strong>ChangeSyncKnowledge</strong></font> (I’ve no idea what this does – it’s not yet documented) </li>     </ul>   </li>    <li><a href="http://technet.microsoft.com/en-us/library/ff607572.aspx" target="_blank"><font face="Courier New"><strong>New-SPContentDatabase</strong></font></a>       <ul>       <li>New Switch Parameter: <font face="Courier New"><strong>ChangeSyncKnowledge</strong></font> (again, not yet documented) </li>     </ul>   </li>    <li><a href="http://technet.microsoft.com/en-ie/library/ff607915(en-us).aspx" target="_blank"><font face="Courier New"><strong>Move-SPSite</strong></font></a>       <ul>       <li>New Parameter: <font face="Courier New"><strong>RbsProviderMapping &lt;Hashtable&gt;</strong></font>           <ul>           <li>From TechNet: “Used to move an RBS-enabled site collection from one RBS-enabled content database to another RBS-enabled content database without moving the underlying BLOB content. If the content database has more than one RBS provider associated with it, you must specify all providers. The same providers must be enabled on the target content database and the source content database.” </li>         </ul>       </li>     </ul>   </li>    <li><a href="http://technet.microsoft.com/en-us/library/ff608122.aspx" target="_blank"><font face="Courier New"><strong>New-SPPerformancePointServiceApplication</strong></font></a>       <ul>       <li>New Parameter: <font face="Courier New"><strong>AnalyticResultCacheMinimumHitCount &lt;Int32&gt;</strong></font> (not yet documented but I think it’s fairly obvious what it does) </li>        <li>New Parameters: <font face="Courier New"><strong>DatabaseServer &lt;string&gt;</strong></font>, <font face="Courier New"><strong>DatabaseName &lt;string&gt;</strong></font>, <font face="Courier New"><strong>DatabaseFailoverServer &lt;string&gt;</strong></font>, <font face="Courier New"><strong>DatabaseSQLAuthenticationCredential &lt;PSCredential&gt;</strong></font>           <ul>           <li>Can I get a hurray for this! This was the only Service Application that didn’t allow us to set the database information when we created it so we were left with this nasty GUID in the name. Hurray! We can finally get rid of the last database GUID! Woohoo! </li>         </ul>       </li>     </ul>   </li>    <li><a href="http://technet.microsoft.com/en-us/library/ff607676.aspx" target="_blank"><font face="Courier New"><strong>Set-SPPerformancePointServiceApplication</strong></font></a>       <ul>       <li>New Parameter: <font face="Courier New"><strong>AnalyticResultCacheMinimumHitCount &lt;Int32&gt;</strong></font> (not yet documented but I think it’s fairly obvious what it does) </li>        <li>New Parameters: <font face="Courier New"><strong>DatabaseServer &lt;string&gt;</strong></font>, <font face="Courier New"><strong>DatabaseName &lt;string&gt;</strong></font>, <font face="Courier New"><strong>DatabaseFailoverServer &lt;string&gt;</strong></font>, <font face="Courier New"><strong>DatabaseSQLAuthenticationCredential &lt;PSCredential&gt;</strong></font>, <font face="Courier New"><strong>DatabaseUseWindowsAuthentication</strong></font> </li>     </ul>   </li>    <li><a href="http://technet.microsoft.com/en-us/library/ff607890.aspx" target="_blank"><font face="Courier New"><strong>Remove-SPWeb</strong></font></a>       <ul>       <li>New Switch Parameter: <font face="Courier New"><strong>Recycle</strong></font>           <ul>           <li>That’s right, you can in fact cause an <font face="Courier New">SPWeb</font> to go to the new recycle bin by simply providing this switch parameter. </li>         </ul>       </li>     </ul>   </li>    <li><a href="http://technet.microsoft.com/en-us/library/ff607547.aspx" target="_blank"><font face="Courier New"><strong>Update-SPProfilePhotoStore</strong></font></a> (I think this one is a bit of mess and may need a CU or two but I could just be reading the code wrong – it is kind of late right now)       <ul>       <li><font color="#ff0000">Update 6/29/2011: From Spence Harbar: “Update-SPProfilePhotoStore change is to address common bug/issue with resize and is for upgrade scenarios”</font></li>        <li>New Switch Parameter: <font face="Courier New"><strong>CreateThumbnailsForImportedPhotos</strong></font>           <ul>           <li>I’m not entirely sure what this is supposed to do as thumbnails were created previously and will be created without this; however, I should note that they coded this wrong so both of the following syntaxes have the same affect as they are simply checking that the <font face="Courier New">bool?</font> type has a value and not what the value is:               <ul>               <li><font face="Courier New">-CreateThumbnailsForImportedPhotos $true</font> </li>                <li><font face="Courier New">-CreateThumbnailsForImportedPhotos $false</font> </li>             </ul>           </li>         </ul>       </li>        <li>New Switch Parameter: <font face="Courier New"><strong>NoDelete</strong></font>           <ul>           <li>I’m not 100% on this but I believe that the original behavior of this cmdlet was to copy the image and not actually move it (despite the name); they appear to have changed the behavior to delete the original images after the copy but you can preserve the original behavior by simply adding this switch parameter. However, this is *only* true when the <font face="Courier New">CreateThumbnailsForImportedPhotos</font> parameter is provided (in my opinion this is a bug – it should be irrelevant if that parameter is provided). </li>         </ul>       </li>     </ul>   </li> </ul>  <p>Well, that’s all I’ve been able to discover with the core SharePoint Server 2010 cmdlets – I may update this post to account for the Office Web Applications but I don’t currently have that installed on the server in which I just installed SP1 so it may take me a bit to do that analysis. At some point I may write something up to inspect the public classes and their members and do a similar post for the developers out there who want to know what API changes have occurred so keep an eye out for that.</p>  <p>So I think it’s pretty cool that we’ve got some improvements in the PowerShell cmdlets, especially in some of those that have frustrated me when it comes to automated deployments; the real frustrating thing, however, is that some of my just released book content is already out of date! Ugh! Maybe there’ll be a second edition <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://blog.falchionconsulting.com/wp-content/Images/SharePoint-2010-SP1-PowerShell-Changes_12AAD/wlEmoticon-smile.png" /></p>  <p>Happy PowerShelling!</p>  <p>-Gary</p>]]></content:encoded>
			<wfw:commentRss>http://blog.falchionconsulting.com/index.php/2011/06/sharepoint-server-2010-service-pack-1-powershell-changes/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		<feedburner:origLink>http://blog.falchionconsulting.com/index.php/2011/06/sharepoint-server-2010-service-pack-1-powershell-changes/</feedburner:origLink></item>
		<item>
		<title>Getting (and taking ownership of) Checked Out Files using Windows PowerShell</title>
		<link>http://feedproxy.google.com/~r/AutomatingSharePoint/~3/YkTN_RGauek/</link>
		<comments>http://blog.falchionconsulting.com/index.php/2011/06/getting-and-taking-ownership-of-checked-out-files-using-windows-powershell/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 04:55:33 +0000</pubDate>
		<dc:creator>Gary Lapointe</dc:creator>
				<category><![CDATA[SharePoint 2010]]></category>
		<category><![CDATA[Cmdlets]]></category>
		<category><![CDATA[Files]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://blog.falchionconsulting.com/index.php/2011/06/getting-and-taking-ownership-of-checked-out-files-using-windows-powershell/</guid>
		<description><![CDATA[Often when I’m working on a project I need to generate a list of all checked out files and provide that to my client just prior to release to production. Sometimes the client will manually inspect each of them and act as they see fit and other times they’ll ask me to just batch publish [...]]]></description>
			<content:encoded><![CDATA[<p>Often when I’m working on a project I need to generate a list of all checked out files and provide that to my client just prior to release to production. Sometimes the client will manually inspect each of them and act as they see fit and other times they’ll ask me to just batch publish all of them (for which I use my <font face="Courier New">Publish-SPListItems</font> cmdlet). So, how do I generate the report for the client? It’s actually pretty easy using PowerShell and a couple of quick loops. Here’s an example that loops through every Site Collection in the Farm and generates a nice report:</p>  <pre><span style="color: #0000ff">function</span><span style="color: #000000"> </span><span style="color: #5f9ea0">Get-CheckedOutFiles</span><span style="color: #000000">() {
    </span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (</span><span style="color: #800080">$web</span><span style="color: #000000"> </span><span style="color: #0000ff">in</span><span style="color: #000000"> (</span><span style="color: #5f9ea0; font-weight: bold">Get-SPSite</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Limit</span><span style="color: #000000"> </span><span style="color: #800000">All</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">Get-SPWeb</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Limit</span><span style="color: #000000"> </span><span style="color: #800000">All</span><span style="color: #000000">)) {
        </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">Processing Web: $($web.Url)...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
        </span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (</span><span style="color: #800080">$list</span><span style="color: #000000"> </span><span style="color: #0000ff">in</span><span style="color: #000000"> (</span><span style="color: #800080">$web</span><span style="color: #000000">.</span><span style="color: #8b4513">Lists</span><span style="color: #000000"> | ? {</span><span style="color: #800080">$_</span><span style="color: #000000"> </span><span style="color: #ff0000">-is</span><span style="color: #000000"> [</span><span style="color: #008080">Microsoft.SharePoint.SPDocumentLibrary</span><span style="color: #000000">]})) {
            </span><span style="color: #5f9ea0; font-weight: bold">Write-Host</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">`tProcessing List: $($list.RootFolder.ServerRelativeUrl)...</span><span style="color: #800000">&quot;</span><span style="color: #000000">
            </span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (</span><span style="color: #800080">$item</span><span style="color: #000000"> </span><span style="color: #0000ff">in</span><span style="color: #000000"> </span><span style="color: #800080">$list</span><span style="color: #000000">.</span><span style="color: #8b4513">CheckedOutFiles</span><span style="color: #000000">) {
                </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #ff0000">!</span><span style="color: #800080">$item</span><span style="color: #000000">.Url.EndsWith(</span><span style="color: #800000">&quot;</span><span style="color: #800000">.aspx</span><span style="color: #800000">&quot;</span><span style="color: #000000">)) { </span><span style="color: #0000ff">continue</span><span style="color: #000000"> }
                </span><span style="color: #800080">$hash</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> @{
                    </span><span style="color: #800000">&quot;</span><span style="color: #800000">URL</span><span style="color: #800000">&quot;</span><span style="color: #ff0000">=</span><span style="color: #800080">$web</span><span style="color: #000000">.</span><span style="color: #8b4513">Site</span><span style="color: #000000">.</span><span style="color: #8b4513">MakeFullUrl</span><span style="color: #000000">(</span><span style="color: #800000">&quot;</span><span style="color: #800000">$($web.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)</span><span style="color: #800000">&quot;</span><span style="color: #000000">);
                    </span><span style="color: #800000">&quot;</span><span style="color: #800000">CheckedOutBy</span><span style="color: #800000">&quot;</span><span style="color: #ff0000">=</span><span style="color: #800080">$item</span><span style="color: #000000">.CheckedOutBy;
                    </span><span style="color: #800000">&quot;</span><span style="color: #800000">CheckedOutByEmail</span><span style="color: #800000">&quot;</span><span style="color: #ff0000">=</span><span style="color: #800080">$item</span><span style="color: #000000">.CheckedOutByEmail
                }
                </span><span style="color: #5f9ea0; font-weight: bold">New-Object</span><span style="color: #000000"> </span><span style="color: #800000">PSObject</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Property</span><span style="color: #000000"> </span><span style="color: #800080">$hash</span><span style="color: #000000">
            }
            </span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (</span><span style="color: #800080">$item</span><span style="color: #000000"> </span><span style="color: #0000ff">in</span><span style="color: #000000"> </span><span style="color: #800080">$list</span><span style="color: #000000">.</span><span style="color: #8b4513">Items</span><span style="color: #000000">) {
                </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$item</span><span style="color: #000000">.File.CheckOutStatus </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800000">&quot;</span><span style="color: #800000">None</span><span style="color: #800000">&quot;</span><span style="color: #000000">) {
                    </span><span style="color: #0000ff">if</span><span style="color: #000000"> ((</span><span style="color: #800080">$list</span><span style="color: #000000">.</span><span style="color: #8b4513">CheckedOutFiles</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">where</span><span style="color: #000000"> {</span><span style="color: #800080">$_</span><span style="color: #000000">.ListItemId </span><span style="color: #ff0000">-eq</span><span style="color: #000000"> </span><span style="color: #800080">$item</span><span style="color: #000000">.ID}) </span><span style="color: #ff0000">-ne</span><span style="color: #000000"> </span><span style="color: #800080">$null</span><span style="color: #000000">) { </span><span style="color: #0000ff">continue</span><span style="color: #000000"> }
                    </span><span style="color: #800080">$hash</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> @{
                        </span><span style="color: #800000">&quot;</span><span style="color: #800000">URL</span><span style="color: #800000">&quot;</span><span style="color: #ff0000">=</span><span style="color: #800080">$web</span><span style="color: #000000">.</span><span style="color: #8b4513">Site</span><span style="color: #000000">.</span><span style="color: #8b4513">MakeFullUrl</span><span style="color: #000000">(</span><span style="color: #800000">&quot;</span><span style="color: #800000">$($web.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)</span><span style="color: #800000">&quot;</span><span style="color: #000000">);
                        </span><span style="color: #800000">&quot;</span><span style="color: #800000">CheckedOutBy</span><span style="color: #800000">&quot;</span><span style="color: #ff0000">=</span><span style="color: #800080">$item</span><span style="color: #000000">.File.CheckedOutByUser;
                        </span><span style="color: #800000">&quot;</span><span style="color: #800000">CheckedOutByEmail</span><span style="color: #800000">&quot;</span><span style="color: #ff0000">=</span><span style="color: #800080">$item</span><span style="color: #000000">.File.CheckedOutByUser.Email
                    }
                    </span><span style="color: #5f9ea0; font-weight: bold">New-Object</span><span style="color: #000000"> </span><span style="color: #800000">PSObject</span><span style="color: #000000"> </span><span style="font-style: italic; color: #5f9ea0">-Property</span><span style="color: #000000"> </span><span style="color: #800080">$hash</span><span style="color: #000000">
                }
            }
        }
        </span><span style="color: #800080">$web</span><span style="color: #000000">.</span><span style="color: #8b4513">Dispose</span><span style="color: #000000">()
    }
}
</span><span style="color: #5f9ea0">Get-CheckedOutFiles</span><span style="color: #000000"> | </span><span style="color: #5f9ea0; font-weight: bold">Out-GridView</span></pre>

<p>Running the above will generate a fairly nice report with URLs and usernames and whatnot; you could also use the <font face="Courier New"><a href="http://technet.microsoft.com/en-us/library/dd347724.aspx" target="_blank">Export-Csv</a></font> cmdlet to dump the results to a CSV file that you can then hand off to your end-users. One cool thing to point out about this is that it will also show you files that you normally can’t see – that is files that have been created by other users but have never had a check in. This is actually pretty cool and I stumbled upon this when trying to fine tune my <font face="Courier New">Publish-SPListItems</font> cmdlet. You see, if the file has never been checked in then iterating through the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitemcollection.aspx" target="_blank"><font face="Courier New">SPListItemCollection</font></a> object will not reveal the item (or file I should say); this meant that my cmdlet, as it was previously written, was missing a bunch of files. So to work around this all I had to do was add an additional loop to iterate over the collection returned by the <font face="Courier New"><a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spdocumentlibrary.aspx" target="_blank">SPDocumentLibrary</a></font>’s <font face="Courier New"><a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spdocumentlibrary.checkedoutfiles.aspx" target="_blank">CheckedOutFiles</a></font> property. For each <font face="Courier New"><a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spcheckedoutfile.aspx" target="_blank">SPCheckedOutFile</a></font> object in that collection I then call <font face="Courier New"><a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spcheckedoutfile.takeovercheckout.aspx" target="_blank">TakeOverCheckOut()</a></font> to grab the checked out file so that I can then publish.</p>

<p>I use this enough that I decided to turn it into a cmdlet that is now part of my custom extensions. Like the above script, I return back a custom object that contains the full URLs and other&#160; useful information (such as the List, Site, and Site Collection identifiers). I also exposed a <font face="Courier New">TakeOverCheckOut()</font> and <font face="Courier New">Delete()</font> method which simply calls Microsoft’s implementation of those methods.</p>

<p>I called this cmdlet <strong><font face="Courier New">Get-SPCheckedOutFiles</font></strong> (note that I’d previously released this cmdlet under the name <font face="Courier New">Get-SPFilesCheckedOut</font> but have since reworked and renamed that original implementation).</p>

<p>Here’s the full help for the cmdlet:</p>

<div style="background-color: black; height: 400px; color: white; overflow: auto">
  <p><font face="Courier New">PS C:\Users\spadmin&gt; help Get-SPCheckedOutFiles -full</font></p>

  <p><font face="Courier New">NAME 
      <br />Get-SPCheckedOutFiles 

      <br />

      <br />SYNOPSIS 

      <br />Retrieves check out details for a given List, Web, or Site. 

      <br />

      <br />SYNTAX 

      <br />Get-SPCheckedOutFiles [-Site] &lt;SPSitePipeBind&gt; [-AssignmentCollection &lt;SPAssignmentCollection&gt;] [&lt;CommonParameters&gt;] 

      <br />

      <br />Get-SPCheckedOutFiles [-Web] &lt;SPWebPipeBind&gt; [-ExcludeChildWebs &lt;SwitchParameter&gt;] [-AssignmentCollection &lt;SPAssignmentCollection&gt;] [&lt;CommonParameters&gt;] 

      <br />

      <br />Get-SPCheckedOutFiles [[-Web] &lt;SPWebPipeBind&gt;] [-List] &lt;SPListPipeBind&gt; [-AssignmentCollection &lt;SPAssignmentCollection&gt;] [&lt;CommonParameters&gt;] 

      <br />

      <br />

      <br />DESCRIPTION 

      <br />Retrieves check out details for a given List, Web, or Site. 

      <br />

      <br />Copyright 2010 Falchion Consulting, LLC 

      <br />&gt; For more information on this cmdlet and others: 

      <br />&gt; </font><font face="Courier New">http://blog.falchionconsulting.com/</font><font face="Courier New"> 
      <br />&gt; Use of this cmdlet is at your own risk. 

      <br />&gt; Gary Lapointe assumes no liability. 

      <br /></font></p>

  <p><font face="Courier New">PARAMETERS 
      <br />-Site &lt;SPSitePipeBind&gt; 

      <br />Specifies the URL or GUID of the Site to inspect. 

      <br />

      <br />The type must be a valid GUID, in the form 12345678-90ab-cdef-1234-567890bcdefgh; a valid URL, in the form </font><font face="Courier New">http://server_nam</font><font face="Courier New">e; or an instance of a valid SPSite object. 
      <br />

      <br />Required? true 

      <br />Position? 1 

      <br />Default value 

      <br />Accept pipeline input? true (ByValue, ByPropertyName) 

      <br />Accept wildcard characters? false 

      <br />

      <br />-Web &lt;SPWebPipeBind&gt; 

      <br />Specifies the URL or GUID of the Web to inspect. 

      <br />

      <br />The type must be a valid GUID, in the form 12345678-90ab-cdef-1234-567890bcdefgh; a valid URL, in the form </font><font face="Courier New">http://server_nam</font><font face="Courier New">e; or an instance of a valid SPWeb object. 
      <br />

      <br />Required? true 

      <br />Position? 1 

      <br />Default value 

      <br />Accept pipeline input? true (ByValue, ByPropertyName) 

      <br />Accept wildcard characters? false 

      <br />

      <br />-List &lt;SPListPipeBind&gt; 

      <br />The list whose checked out files are to be returned. 

      <br />

      <br />The value must be a valid URL in the form </font><font face="Courier New">http://server_name/lists/listname</font><font face="Courier New"> or /lists/listname. If a server relative URL is provided then the Web parameter must be provided. 
      <br />

      <br />Required? true 

      <br />Position? 1 

      <br />Default value 

      <br />Accept pipeline input? true (ByValue, ByPropertyName) 

      <br />Accept wildcard characters? false 

      <br />

      <br />-ExcludeChildWebs [&lt;SwitchParameter&gt;] 

      <br />Excludes all child sites and only considers the specified site. 

      <br />

      <br />Required? false 

      <br />Position? named 

      <br />Default value 

      <br />Accept pipeline input? false 

      <br />Accept wildcard characters? false 

      <br />

      <br />-AssignmentCollection [&lt;SPAssignmentCollection&gt;] 

      <br />Manages objects for the purpose of proper disposal. Use of objects, such as SPWeb or SPSite, can use large amounts of memory and use of these objects in Windows PowerShell scripts requires proper memory management. Using the SPAssignment object, you can assign objects to a variable and dispose of the objects after they are needed to free up memory. When SPWeb, SPSite, or SPSiteAdministration objects are used, the objects are automatically disposed of if an assignment collection or the Global parameter is not used. 

      <br />

      <br />When the Global parameter is used, all objects are contained in the global store. If objects are not immediately used, or disposed of by using the Stop-SPAssignment command, an out-of-memory scenario can occur. 

      <br />

      <br />Required? false 

      <br />Position? named 

      <br />Default value 

      <br />Accept pipeline input? true (ByValue) 

      <br />Accept wildcard characters? false 

      <br />

      <br />&lt;CommonParameters&gt; 

      <br />This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer and OutVariable. For more information, type, &quot;get-help about_commonparameters&quot;. 

      <br />

      <br />INPUTS 

      <br />

      <br />OUTPUTS 

      <br />

      <br />NOTES 

      <br />

      <br />For more information, type &quot;Get-Help Get-SPCheckedOutFiles -detailed&quot;. For technical information, type &quot;Get-Help Get-SPCheckedOutFiles -full&quot;. 

      <br />

      <br />------------------EXAMPLE------------------ 

      <br />

      <br />PS C:\&gt; Get-SPCheckedOutFiles -Site &quot;</font><a href="http://server_name/&quot;"><font face="Courier New">http://server_name/&quot;</font></a><font face="Courier New"> 
      <br />

      <br />

      <br />This example outputs a list of files that are checked out for the given Site Collection 

      <br />

      <br />

      <br />RELATED LINKS 

      <br />Get-SPFile</font> </p>
</div>

<p>&#160;</p>

<p>In the following example I’m retrieving pages from the root Pages library that are checked out:</p>

<p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blog.falchionconsulting.com/wp-content/Images/84e52f01b2f7_9C49/image.png" width="821" height="367" /></p>

<p>In this example I am running the cmdlet as the <em><strong>aptillon\spadmin</strong></em> user and I’m now able to see the checkout by the user <em><strong>aptillon\glapointe</strong></em>. I ran the cmdlet twice so you could see the default tabular view as well as the more detailed view. Again, you could easily use the <font face="Courier New">Export-Csv</font> cmdlet to dump this information to a file that you can provide your end-users.</p>

<p>I hope you find this cmdlet useful – it personally has proven invaluable to me, particularly when working on anonymous access internet sites as end-users are notorious about creating pages and not getting them checked in.</p>

<p>P.S. With this release the <font face="Courier New">Publish-SPListItems</font> cmdlet has been updated to now consider files that don’t have any existing check-ins.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.falchionconsulting.com/index.php/2011/06/getting-and-taking-ownership-of-checked-out-files-using-windows-powershell/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://blog.falchionconsulting.com/index.php/2011/06/getting-and-taking-ownership-of-checked-out-files-using-windows-powershell/</feedburner:origLink></item>
	</channel>
</rss>

