SharePoint 2010 Cookbook: PowerShell Script to Automatically Deploy Bamboo Web Parts

Life is too short to wait! Being a Support Engineer at Bamboo Solutions, my everyday work involves installing and testing Web Parts. Basically, I need to install the Web Part to different environments and try to duplicate the same issues that customers are experiencing. Then, when the fix is implemented, I will install it again to check repeatedly until I can confirm that the fix is OK. This obviously takes a lot of time. The Bamboo Solutions Web Part Setup is good because it helps us know what happens through each step. But what if we are already familiar with the process and want to deploy the Web Part quickly? In this post, I will demonstrate how we can easily install a Bamboo Solutions Web Part using PowerShell script and save some time to do more valuable things.

Challenge:

How can I speed up the manual installation of Bamboo Web Parts and automatically deploy Web Parts via a PowerShell script?

Solutions:

Many articles on the Internet explain how to deploy a solution using a PowerShell script. One such article which I found to be particularly useful is from Sohel’s Blog:

http://ranaictiu-technicalblog.blogspot.com/2010/05/sharepoint-2010-deployment-powershell.html

So I’m not going to cover the basics here but instead talk about how we can implement the script to run with the Bamboo Solutions Web Part setup package.

First, verify that you possess the following permissions:

  • SharePoint Farm Administrator.
  • Local Server Administrator on all Web servers.
  • db_owner permission on the content database

In this example, I will deploy Calendar Plus Web Part. After clicking to download the Web Part solution from the Bamboo Solutions store, we are given an .exe file named “HW20.R4.SP2010.SL.exe”. Running it will extract all content to a folder named “HW20.R4.SP2010.SL” and will also open up the Web Part Setup as shown below:

Close the Web Part Setup and take a look at the extracted folder:

We will need to deploy all of the solutions (.wsp) under this folder, except Web License Manager. The logic is simple:

  • Find all .wsp solutions under this folder and filter out the Web License Manager solution.
  • For each solution, check whether it has already been deployed. If yes, remove it.
  • If the solution has not been deployed, install it.

Here is the deployment script (DeployBambooWebpart.ps1):

Add-PsSnapin Microsoft.SharePoint.PowerShell

Start-SPAssignment -Global    # This cmdlet takes care of the disposable objects to prevent memory leak.

function WaitForJobToFinish ([string]$solutionName)    # This function waits for the deployment job to finish before doing the next command.
{
    $JobName = "*solution-deployment*$solutionName*"
    $job = Get-SPTimerJob | ?{ $_.Name -like $JobName }
    if ($job -eq $null)
    {
        Write-Host "Timer job not found"
    }
    else
    {
        $JobFullName = $job.Name
        Write-Host -NoNewLine "Waiting to finish job $JobFullName"

        while ((Get-SPTimerJob $JobFullName) -ne $null)
        {
            Write-Host -NoNewLine .
            Start-Sleep -Seconds 2
        }
        Write-Host  "Finished waiting for job.."
    }
}

function InstallSolution ([string]$solutionName,[string]$solutionPath)        # This function is used to install a solution.
{
    $solution=Get-SPSolution -Identity $solutionName -ErrorAction:SilentlyContinue    # Get the solution.
    if ($solution -ne $null)        # Check whether the solution exists in the Solutions Store.
    {
    if ($solution.Deployed)        # Check whether the solution is already deployed.
    {
        write-Host $solutionName "is already deployed, going to uninstall it"
        write-Host "Retracting" $solutionName

        if ($solution.ContainsWebApplicationResource)    # If the solution contains Web Application Resource, use this command.
            {
        Uninstall-SPSolution -identity $solutionName -allwebapplication -confirm:$false
            }
            else                        # Otherwise, use this command.
            {
        Uninstall-SPSolution -identity $solutionName -confirm:$false
            }

        Write-Host "Waiting for job to finish"
                 WaitForJobToFinish $solutionName
              }

              Write-Host "Removing" $solutionName            # Remove solution from store.
               Remove-SPSolution –Identity $solutionName -confirm:$false
    }

    Write-Host "Adding" $solutionName "to the Solutions Store"    # Add solution to Solutions Store.
    Add-SPSolution -LiteralPath $solutionPath

    $solution=Get-SPSolution -Identity $solutionName        # Assign solution to a variable.

    Write-Host "Deploying" $solutionName
    if ($solution.ContainsWebApplicationResource)        # If the solution contains Web Application Resource, use this command.
    {
        Install-SPSolution –Identity $solutionName –allwebapplication –GACDeployment -CASPolicies
    }
    else                                # Otherwise, use this command.
    {
        Install-SPSolution –Identity $solutionName –GACDeployment -CASPolicies
    }

    Write-Host "Waiting for job to finish"
    WaitForJobToFinish $solutionName
}

$currentDir=$args[0]    # Assign the script parameter (current directory)

$solutionFiles=Get-ChildItem $currentDir*.* -recurse -include *.wsp -exclude Bamboo.UI.Licensing.wsp    # Get all solutions under this directory and filter out Bamboo Web License Manager.

foreach ($solutionFile in $solutionFiles)            # For each solution found, install it
{
    $solutionName=$solutionFile.Name
    $solutionPath=$solutionFile.FullName

    InstallSolution $solutionName $solutionPath
    Get-SPSolution -Identity $solutionName | select Deployed    # Display deployment result.
    write-Host ""                            # Add an empty line and go on to the next solution
}

Stop-SPAssignment -Global

Remove-PsSnapin Microsoft.SharePoint.PowerShell

write-Host "Finished script."

We can then create a batch file to run this script as follows:

cd /d %~dp0
powershell -noexit -file    ".DeployBambooWebPart.ps1" "%CD%"

Put the script and batch file in the extracted folder (HW20.R4.SP2010.SL) and run the batch file to install this Web Part.

Notes:

  • This method works with both SharePoint 2010 Foundation and Server.
  • This script has not been tested with all Bamboo Solutions Web Parts. Theoretically, it should work with most of them, but it will not work with all of them. For example, if we try to deploy Bamboo List Rollup Web Part R5.0 using this script, we will get an error because some solutions need to be deployed prior to others.

See Also:


 

SharePoint Online

The cloud parts are functional components that extend your SharePoint Online environment in Microsoft 365.

Supports Classic and Modern sites for SharePoint Online/Microsoft 365

Small Business Pricing and Discounts

SharePoint

Top SharePoint Online Products

Experience greater power and savings by bundling our SharePoint apps and cloud parts.


Calendar Plus


Carousel


Employee Directory Plus


Org Chart Plus


Simple Search


Tabify


Tree View

 

On-Premises Only

These web parts extend SharePoint beyond its out-of-the-box capabilities by tailoring it to your requirements with Bamboo Solution’s growing portfolio of SharePoint Web Parts.

SharePoint 2016, 2019, 2022 – Classic Pages Only

SharePoint

Top On-Premises Only Products

Experience greater power and savings by bundling our SharePoint apps and web parts.


Calendar Plus


Data Viewer


Password Change


Password Expiration


Password Reset

 

Our team of Microsoft 365 Technology Consultants helps you get the most out of your Microsoft technology, we have the best Microsoft 365 talent to streamline your organization.

Consulting to Streamline Your Department

M365 Plus

Managed Services

Microsoft 365

Consulting to Streamline Your Department


Human Resources


Information Technology


Marketing Campaigns


Healthcare


Sales

 

Our Consultants Have What You Need

Federal Contractors