<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	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/"
	>

<channel>
	<title>Beij Solutions &#187; PowerShell</title>
	<atom:link href="http://www.beijsolutions.nl/category/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.beijsolutions.nl</link>
	<description></description>
	<lastBuildDate>Mon, 19 Nov 2012 11:45:40 +0000</lastBuildDate>
	<language>nl-NL</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>SharePoint 2010 Deployment script using Powershell</title>
		<link>http://www.beijsolutions.nl/2010/11/sharepoint-2010-deployment-script-using-powershell/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sharepoint-2010-deployment-script-using-powershell</link>
		<comments>http://www.beijsolutions.nl/2010/11/sharepoint-2010-deployment-script-using-powershell/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 09:44:00 +0000</pubDate>
		<dc:creator><![CDATA[markbeij]]></dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SharePoint 2010]]></category>

		<guid isPermaLink="false">http://www.beijsolutions.nl/?p=13</guid>
		<description><![CDATA[For a project I was working on last month, I needed a way to deploy SharePoint 2010 solutions in a controlled manner. Thanks to Gary Lapointe I was quickly up to speed to create my first Powershell Script. The script &#8230; <a href="http://www.beijsolutions.nl/2010/11/sharepoint-2010-deployment-script-using-powershell/">Verder lezen <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>For a project I was working on last month, I needed a way to deploy SharePoint 2010 solutions in a controlled manner.<br />
Thanks to Gary Lapointe I was quickly up to speed to create my first Powershell Script. The script he provided in his <a href="http://stsadm.blogspot.com/2010/06/deploying-sharepoint-2010-solution.html">post</a> makes it possible to deploy solutions using a xml configuration file. But I needed a script that activates the features as well, so I extended Gary&#8217;s script.</p>
<p><strong>solutions.xml</strong></p>
<blockquote><p>&lt;Solutions&gt;<br />
&lt;Solution Path=&#8221;[[Solution1.wsp]]&#8221; CASPolicies=&#8221;false&#8221; GACDeployment=&#8221;true&#8221;&gt;<br />
&lt;WebApplications&gt;<br />
&lt;WebApplication Url=&#8221;[[URL]]:8080&#8243;&gt;<br />
&lt;Feature Name=&#8221;1116af9b-e3b5-498e-9706-1b67b7b60c43&#8243; Url=&#8221;[[URL]]&#8221; /&gt;<br />
&lt;Feature Name=&#8221;2220d8aa-2d25-47bb-8d44-29a45caaa4ce&#8221; Url=&#8221;[[URL]]&#8221; /&gt;<br />
&lt;Feature Name=&#8221;3330364b-e879-4fee-b103-3c3dd10c0a1c&#8221; Url=&#8221;[[URL]]&#8221; /&gt;<br />
&lt;Feature Name=&#8221;444a36e0-d249-469a-ba46-4ca7baa10ea6&#8243; Url=&#8221;[[URL]]&#8221; /&gt;<br />
&lt;/WebApplication&gt;<br />
&lt;/WebApplications&gt;<br />
&lt;/Solution&gt;<br />
&lt;Solution Path=&#8221;[[Solution2.wsp]]&#8221; CASPolicies=&#8221;false&#8221; GACDeployment=&#8221;true&#8221;&gt;<br />
&lt;WebApplications&gt;<br />
&lt;WebApplication Url=&#8221;[[URL]]&#8221;&gt;<br />
&lt;Feature Name=&#8221;Feature1&#8243; Url=&#8221;[[URL]]&#8221; /&gt;<br />
&lt;/WebApplication&gt;<br />
&lt;/WebApplications&gt;<br />
&lt;/Solution&gt;<br />
&lt;/Solutions&gt;</p></blockquote>
<p><strong>Deplopy.ps1</strong></p>
<blockquote><p>$solutionfile = &#8220;solutions.xml&#8221;</p></blockquote>
<p>if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )<br />
{<br />
Add-PSSnapin Microsoft.SharePoint.PowerShell<br />
}</p>
<p>function Install-Solutions([string]$configFile)<br />
{<br />
if ([string]::IsNullOrEmpty($configFile)) { return }</p>
<p>$solutionsConfig = Get-Content $configFile<br />
if ($solutionsConfig -eq $null) { return }</p>
<p>$solutionsConfig.Solutions.Solution | ForEach-Object {</p>
<p>$_.WebApplications.WebApplication | ForEach-Object {<br />
Write-Host $_.Url<br />
$_.Feature | ForEach-Object {<br />
Write-Host $_.Name<br />
[string]$name = $_.Name<br />
[string]$url = $_.Url<br />
Write-Host Deactivate-Feature $name $url<br />
Deactivate-Feature $name $url<br />
}<br />
}</p>
<p>[string]$path = $_.Path<br />
[bool]$gac = [bool]::Parse($_.GACDeployment)<br />
[bool]$cas = [bool]::Parse($_.CASPolicies)<br />
$webApps = $_.WebApplications.WebApplication<br />
Write-Host Install-Solution $path $gac $cas $webApps.Url<br />
Install-Solution $path $gac $cas $webApps.Url</p>
<p>$_.WebApplications.WebApplication | ForEach-Object {<br />
$_.Feature | ForEach-Object {<br />
[string]$name = $_.Name<br />
[string]$url = $_.Url<br />
Activate-Feature $name $url<br />
}<br />
}<br />
}<br />
}</p>
<p>function Deactivate-Feature([string]$featurename, [string]$url)<br />
{<br />
#Check for Sitecollection-scoped feature<br />
$feature = Get-SPFeature $featurename -Site $url -ErrorAction SilentlyContinue<br />
if ($feature -eq $null) {<br />
#Check for Web-scoped feature<br />
$feature = Get-SPFeature $featurename -Web $url -ErrorAction SilentlyContinue<br />
}</p>
<p>if ($feature -ne $null) {<br />
Write-Host Disable-SPFeature -Identity $featurename -Url $url<br />
Disable-SPFeature -Identity $featurename -Url $url -Confirm:$false<br />
}</p>
<p>}</p>
<p>function Activate-Feature([string]$featurename, [string]$url)<br />
{<br />
$feature = Get-SPFeature $featurename -ErrorAction SilentlyContinue<br />
if ($feature -ne $null) {<br />
Write-Host Enable-SPFeature -Identity $featurename -Url $url<br />
Enable-SPFeature -Identity $featurename -Url $url<br />
}<br />
}</p>
<p>function Install-Solution([string]$path, [bool]$gac, [bool]$cas, [string[]]$webApps = @())<br />
{<br />
$spAdminServiceName = &#8220;SPAdminV4&#8243;</p>
<p>[string]$name = Split-Path -Path $path -Leaf<br />
$solution = Get-SPSolution $name -ErrorAction SilentlyContinue</p>
<p>if ($solution -ne $null) {<br />
#Retract the solution<br />
if ($solution.Deployed) {<br />
Write-Host &#8220;Retracting solution $name&#8230;&#8221;<br />
if ($solution.ContainsWebApplicationResource) {<br />
$solution | Uninstall-SPSolution -AllWebApplications -Confirm:$false<br />
} else {<br />
$solution | Uninstall-SPSolution -Confirm:$false<br />
}<br />
Stop-Service -Name $spAdminServiceName<br />
Start-SPAdminJob -Verbose<br />
Start-Service -Name $spAdminServiceName</p>
<p>#Block until we&#8217;re sure the solution is no longer deployed.<br />
do { Start-Sleep 2 } while ((Get-SPSolution $name).Deployed)<br />
}</p>
<p>#Delete the solution<br />
Write-Host &#8220;Removing solution $name&#8230;&#8221;<br />
Get-SPSolution $name | Remove-SPSolution -Confirm:$false<br />
}</p>
<p>#Add the solution<br />
Write-Host &#8220;Adding solution $name&#8230;&#8221;<br />
$solution = Add-SPSolution $path</p>
<p>#Deploy the solution<br />
if (!$solution.ContainsWebApplicationResource) {<br />
Write-Host &#8220;Deploying solution $name to the Farm&#8230;&#8221;<br />
$solution | Install-SPSolution -GACDeployment:$gac -CASPolicies:$cas -Confirm:$false<br />
} else {<br />
if ($webApps -eq $null -or $webApps.Length -eq 0) {<br />
Write-Warning &#8220;The solution $name contains web application resources but no web applications were specified to deploy to.&#8221;<br />
return<br />
}<br />
$webApps | ForEach-Object {<br />
Write-Host &#8220;Deploying solution $name to $_&#8230;&#8221;<br />
$solution | Install-SPSolution -GACDeployment:$gac -CASPolicies:$cas -WebApplication $_ -Confirm:$false<br />
}<br />
}<br />
Stop-Service -Name $spAdminServiceName<br />
Start-SPAdminJob -Verbose<br />
Start-Service -Name $spAdminServiceName</p>
<p>#Block until we&#8217;re sure the solution is deployed.<br />
do { Start-Sleep 2 } while (!((Get-SPSolution $name).Deployed))<br />
}</p>
<p>function Get-ScriptDirectory<br />
{<br />
$Invocation = (Get-Variable MyInvocation -Scope 1).Value<br />
Split-Path $Invocation.MyCommand.Path<br />
}</p>
<p>Install-Solutions($solutionfile);</p>
]]></content:encoded>
			<wfw:commentRss>http://www.beijsolutions.nl/2010/11/sharepoint-2010-deployment-script-using-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
