Category Archives: Share Point 2010

Webinar on 10/19/2011 at 2pm Eastern – Using SharePoint Designer in the ‘Real World’

This is a good opportunity to get free webinar by someone like Asif Rehmani. Following is the detail of the event as received.

See more at http://bytebeats.com/2011/10/19/webinar-on-10192011-at-2pm-eastern-using-sharepoint-designer-in-the-real-world/

SharePoint Automation – Power Shell Scripts

Hi,

How often I think about PowerShell Scripts while working on SharePoint 2007 and deploying solutions using Stsadm. Though, it worked well for me, but never got control as promissed by the powershell scripts.

Recently, I got chance to start working and ext exploring my experiences with PowerShell Scripts for deployment of SharePoint 2010 solution and doing a lot with Microsoft .Net object model siting outside Visual Studio and working in colorful Power Shell Snap In 🙂

Today, I’m gonna share a piece of work that we (SharePoint developers) needs to deal with almost in every SharePoint project, and that’s the deployment of SharePoint Solutions. You may find the contents of this post on google, but I tried to keep things simple and planned.

First of all, for those who are new to Power Shall, you may be wondering about the Commands that you can use with power shell. I use a better way to keep them with me, try the following command in Power Shell to dump all available SharePoint commands in a text file.

Get-Command -module Microsoft.SharePoint.PowerShell > textfilename.txt

Once You have all the commands, its easy for you to go and explore commands based on your requirements, I would say the Get-help is really helpful here 🙂

Now let’s play with Power shell and deploy our Solution files for the SharePoint Farm.

Lets take the case where we have some solution files, and we want to write a script that will Add and deploy solution files to specified Farm or Web.
To make it clean and dynamic I use a xml Configuration file for deployment.

<ProjectName>
<Solutions>
<Solution Name=”Usman.SP.Projects.Utilities.wsp” Path=”C:\Users\afzalu\PS_Scripts\Installer\Usman.SP.Projects.Utilities.wsp” CASPolicies=”false” GACDeployment=”true”>    </Solution>
<Solution Name=”Usman.SP.Projects.Branding.wsp” Path=”C:\Users\afzalu\PS_Scripts\Installer\Usman.SP.Projects.Branding.wsp” CASPolicies=”false” GACDeployment=”true”>    </Solution>
<Solution Name=”Usman.SP.Projects.Core.wsp” Path=”C:\Users\afzalu\PS_Scripts\Installer\Usman.SP.Projects.Core.wsp” CASPolicies=”false” GACDeployment=”true”>    </Solution>
<Solution Name=”Usman.SP.Projects.Pages.wsp” Path=”C:\Users\afzalu\PS_Scripts\Installer\Usman.SP.Projects.Pages.wsp” CASPolicies=”false” GACDeployment=”true”>    </Solution>
<Solution Name=”Usman.SP.Projects.RequestHandling.wsp” Path=”C:\Users\afzalu\PS_Scripts\Installer\Usman.SP.Projects.RequestHandling.wsp” CASPolicies=”false” GACDeployment=”true”>    </Solution>
<Solution Name=”Usman.SP.Projects.WebStructure.wsp” Path=”C:\Users\afzalu\PS_Scripts\Installer\Usman.SP.Projects.WebStructure.wsp” CASPolicies=”false” GACDeployment=”true”>    </Solution>
<Solution Name=”Usman.SP.Projects.Presentation.wsp” Path=”C:\Users\afzalu\PS_Scripts\Installer\Usman.SP.Projects.Presentation.wsp” CASPolicies=”false” GACDeployment=”true”>
<WebApplications>
</WebApplications>
</Solution>
<Solution Name=”Usman.SP.Projects.Sites.wsp” Path=”C:\Users\afzalu\PS_Scripts\Installer\Usman.SP.Projects.Sites.wsp” CASPolicies=”false” GACDeployment=”true”>
<WebApplications>
</WebApplications>
<Solution>
</Solutions>

</ProjectName>

For Now, I just take an example where I need to deploy the solution, but ofcourse with this design you can also do feature activation and other webapplication chnages (we will do that in some other post).

Now let’s see how easily we can add a Power Shell Script to add these solution to specific WebApplication or Farm

# add SharePoint Powershell snapin
add-PSSnapin Microsoft.Sharepoint.powershell
write-host “———————————————————-” -foregroundcolor Green
write-host “Deploying Soultions” -foregroundcolor Green

if($args){

# Getting web.Config File

$configFile = $args[0];

if ([string]::IsNullOrEmpty($configFile)) { return }

[xml]$solutionsConfig = Get-Content $configFile

if ($solutionsConfig -eq $null) { return }

$solutionsConfig.DLW.Solutions.Solution | ForEach-Object{
[string]$path = $_.Path
[bool]$gac = [bool]::Parse($_.GACDeployment)
[bool]$cas = [bool]::Parse($_.CASPolicies)
$webApps = $_.WebApplications.WebApplication

#Add the solution

$spAdminServiceName = “SPAdminV4”
[string]$name = Split-Path -Path $path -Leaf
$solution = Get-SPSolution $name -ErrorAction SilentlyContinue
Write-Host “Adding solution $name…”
$solution = Add-SPSolution $path

#Deploy the solution

if (!$solution.ContainsWebApplicationResource) {
Write-Host “Deploying solution $name to the Farm…”
$solution | Install-SPSolution -GACDeployment:$gac -CASPolicies:$cas -Confirm:$false
}
else {
if ($webApps -eq $null -or $webApps.Length -eq 0) {
Write-Warning “The solution $name contains web application resources but no web applications were specified to deploy to.”
return
}
$webApps | ForEach-Object {
Write-Host “Deploying solution $name to $_…”
$solution | Install-SPSolution -GACDeployment:$gac -CASPolicies:$cas -WebApplication $_ -Confirm:$false
}
}
# Restarting the Service
Stop-Service -Name $spAdminServiceName
Start-SPAdminJob -Verbose
Start-Service -Name $spAdminServiceName

#Block until we’re sure the solution is deployed.

do { Start-Sleep 2 } while (!((Get-SPSolution $name).Deployed))
} #End of $solutionsConfig.Solutions.Solution | ForEach-Object
}
write-host “Solutions Deployed Successfully” -foregroundcolor Green

write-host “———————————————————–” -foregroundcolor Green

Sorry for Formating, but it takes too much time so I prefer sharing things rather than spending lots of time on formating.
Once you run the above code you will see a very informative Power Shell Window, that will show you all the deployment setps in a friendly way so your deployement team can really enjoy the deployment.
You can use the below code to uninstall and delete the solution files using the same XML file

# add SharePoint Powershell snapin

add-PSSnapin Microsoft.Sharepoint.powershell

write-host “———————————————————-” -foregroundcolor Green

write-host “Deleting Soultions” -foregroundcolor Green

if($args){

# Getting web.Config File

$configFile = $args[0];

if ([string]::IsNullOrEmpty($configFile)) { return }

[xml]$solutionsConfig = Get-Content $configFile

if ($solutionsConfig -eq $null) { return }

$solutionsConfig.DLW.Solutions.Solution | ForEach-Object{

[string]$name = $_.Name

$spAdminServiceName = “SPAdminV4”

$solution = Get-SPSolution $name

# Un-Install Solutions

if($solution.Deployed){

if (!$solution.ContainsWebApplicationResource) {

Write-Host “Un-Installing solution $name from the Farm…”

$solution | UnInstall-SPSolution -Confirm:$false

}

else{

Write-Host “Un-Installing solution $name …”

$solution | UnInstall-SPSolution -AllWebApplications:$true -Confirm:$false

}

Stop-Service -Name $spAdminServiceName

Start-SPAdminJob -Verbose

Start-Service -Name $spAdminServiceName

#Block until we’re sure the solution is deployed.

do { Start-Sleep 2 } while (((Get-SPSolution $name).Deployed))

}

} #End of $solutionsConfig.Solutions.Solution | ForEach-Object

# Remove Solutions

$solutionsConfig.DLW.Solutions.Solution | ForEach-Object{

if(!$solution.Deployed){

[string]$name = $_.Name

Write-Host “Getting uninstall solution $name…” -foregroundcolor YELLOW

$unInstallSolution = Get-SPSolution $name

$unInstallSolution | Remove-SPSolution -Confirm:$false

Write-Host “Solutoin $name… Removed” -foregroundcolor YELLOW

}

}

}

write-host “Solutions Deleted Successfully” -foregroundcolor Green

write-host “———————————————————–” -foregroundcolor Green

Activate Site Directory Site Template in SharePoint 2010

If you are wondering about the “Site Directory Sit Template” in SharePoint 2010, then follow this blog post to use this feature onto your Share Point Server.

Actually, this feature is made Hidden by Intentionality for upgrade purpose from Share Point Server 2003 to 2010, and you need to make this feature visible and than activate for your specific web site.

Follow these steps to get rid of Hidden Directory Site Template Feature.

1. Open C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\1033\XML

2. Open webtempsps.xml for Eidt

3. Find section for “Site Directory” and change Hidden value

<Configuration ID="0" Title=”Site Directory” Type=”0″ Hidden=”FALSE” ImageUrl=”/_layouts/1033/images/template_site_dir.png” Description=”A site for listing and categorizing important sites in your organization. It includes different views for categorized sites, top sites, and a site map.” DisplayCategory=”Enterprise” VisibilityFeatureDependency=”5F3B0127-2F1D-4cfd-8DD2-85AD1FB00BFC”>

4. After that open command prompt and browse to
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN

5. Activate the feature ” SharePoint Server Publishing Infrastructure” onto your site (if not activated earlier)

6. Run following commaned:
stsadm.exe -o activatefeature -id 5F3B0127-2F1D-4cfd-8DD2-85AD1FB00BFC –url http://yoursite

After these steps, go to your site and Create a new site using Site Directory Site Template, it is there now :-).

Useful Information, Rate It.