PowerShell and CSOM: Tool to Import Design Package WSP with activation of required feature for SharePoint Online-O365


This is my initial article to address the challenges around automation of SharePoint Online deployment.
Below artifacts can be developed through this technique,

  • List Definition
  • List Instance
  • Web part development
  • Template Development
  • JS Link webpart development
  • Remote Timer Job
  • Remote Event Handler
  • etc.
You can combine any set of above artifacts in to a WSP solution.

Tool Description

This tool is responsible for activating the mandatory features for any site other than Publishing and Installing or Upgrading the WSP Solution to SPO O365 tenant site collection.

Below are the features activated using this tool,

1. SharePoint Server Publishing Infrastructure

2. SharePoint Server Publishing

You can also extend the logic for activation of other feature by calling below,

Enable-SPOFeature -sSiteColUrl $SiteURL -spoCtx $Context -sFeatureGuid $FeatureGuidServerPublishing -IsSiteScope $False
Use below parameters while calling method,
$SiteURL – site collection URL
$Context – Context of the site
$sFeatureGuid – Guid of feature to be activated
$True or $False – is site collection level feature


Download Source

Click here to download Source

Authentication and Execution Model

Authentication and Execution Model
As depicted in above model diagram shows how PowerShell based tool help to authenticate, connect to SPO and on validation it helps to execute the CSOM based commandlets and deploy the WSP to perform deployment of different artifacts as packaged. Below are major component as depicted in diagram,
A. SharePoint Online Mangement Shell
B. Authentication component – while connecting to SharePoint Online tenant
C. Validated Admin enable to process the execution to SPO
D.SharePoint Tenant – Site Collection  Targeted destination for deployment

Run Execution Command

Below is the command will be helpful to execute the tool. Kindly modify the parameters before execution,

.\ApplyDesignPackageInstalltionAndUpgradeWSP.ps1 -User admin@xxxxxx.onmicrosoft.com -SiteURL "https://xxxxxx.sharepoint.com/sites/xxxxxx" -wspFullFilePath "C:\Amjad\<WSPBuildName>.wsp"  -WspFileName "<WSPBuildName>.wsp" -wspPackageName "<WSPBuildName>" -majorVersion 1 -minorVersion 0
 Parameters details are as below,

Script can accept 7 parameters from the command line#

# User – mandatory – Administrator login ID for the tenant we are querying

# SiteURL – mandatory – Destination Site URL for the tenant we are querying

# wspFullFilePath – mandatory – Path of WSP location to upload from

# WspFileName – mandatory – Name of WSP file

# wspPackageName – Optional – WSP Package Name for Solution Gallery

# majorVersion – Optional – majorVersion of the Build demployment or upgrade

# majorVersion – Optional – minorVersion of the Build demployment or upgrade#


Hope this article helps.


O365 and SharePoint: Remove the WebPart from a site by using PowerShell

As we aware the WebpartManager class is helpful in Server side object model. The question popped-up in my mind “Is this possible by using PowerShell scripting?“.

I found answer as “Yes”.

Below is the code snippet to remove webpart from a site by specifying webpartId and site url,

$siteURL = “ht tp://sharePoint/sites/specialsite”; # first constant: site URL
$webpartId = “<guid of your choice for webpart>; # second argument: webpart GUID
$pagepath = “/default.aspx” # change page name or page path here
$pageURL = $siteURL + $pagepath
write-host “Processing site: “, $siteURL
Write-host “Processing page: ” , $pageURL
write-host “Processing webpart ID: ” , $webpartID
$site=new-object Microsoft.SharePoint.SPSite($siteURL)
$webpartmanager=$web.GetLimitedWebPartManager($pageURL, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
write-host “Finished.”

O365 and SharePoint: List of WebParts in all sites of Web Application by using PowerShell

As we aware the WebpartManager class is helpful in Server side object model. The question popped-up in my mind “Is this possible by using PowerShell scripting?“.

I found answer as “Yes”.

Below is the code snippet to achieve the same,

$oContentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService;
[Microsoft.SharePoint.Administration.SPWebApplicationCollection]$waCollection = $oContentService.WebApplications;
$log = “.\results.txt” # output file name and path
$pagepath = “/default.aspx” # you can change page name or page path
“Site URL; WebPart Title ; Webpart ID” | out-file $log
$waCollection1 = $waCollection | where-object {$_.IsAdministrationWebApplication -eq $FALSE}
foreach ($wa in $waCollection1)
foreach ($obj in $wa.Sites)
write-host “Processing site: ” , $siteURL
$siteURL = $obj.URL

$site=new-object Microsoft.SharePoint.SPSite($siteURL)

$pageURL = $siteURL + $pagepath
$webpartmanager=$web.GetLimitedWebPartManager($pageURL, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
foreach ($webpart in $webpartmanager.WebParts)
$siteURL + “; ” + $webpart.Title + ” ; ” + $webpart.ID | out-file $log -append

O365: SPO Cmdlets for PowerShell

Below is the list of few important Cmdlets,

  • Site Groups
  • Users
    • Add-SPOUser – Add a user to an existing Site Collection Site Group.
    • Get-SPOUser – Get an existing user.
    • Remove-SPOUser – Remove an existing user from the Site Collection or from an existing Site Collection Group.
    • Set-SPOUser – Set whether an existing Site Collection user is a Site Collection administrator or not.
    • Get-SPOExternalUser – Returns external users from the tenant’s folder.
    • Remove-SPOExternalUser – Removes a collection of external users from the tenancy’s folder.
  • Site Collections
    • Get-SPOSite – Retrieve an existing Site Collection.
    • New-SPOSite – Create a new Site Collection.
    • Remove-SPOSite – Move an existing Site Collection to the recycle bin.
    • Repair-SPOSite – If any failed Site Collection scoped health check rules can perform an automatic repair then initiate the repair.
    • Set-SPOSite – Set the Owner, Title, Storage Quota, Storage Quota Warning Level, Resource Quota, Resource Quota Warning Level, Locale ID, and/or whether the Site Collection allows Self Service Upgrade.
    • Test-SPOSite – Run all Site Collection health check rules against the specified Site Collection.
    • Upgrade-SPOSite – Upgrade the Site Collection. This can do a build-to-build (e.g., RTM to SP1) upgrade or a version-to-version (e.g., 2010 to 2013) upgrade. Use the -VersionUpgrade parameter for a version-to-version upgrade.
    • Get-SPODeletedSite – Get a Site Collection from the recycle bin.
    • Remove-SPODeletedSite – Remove a Site Collection from the recycle bin (permanently deletes it).
    • Restore-SPODeletedSite – Restores an item from the recycle bin.
    • Request-SPOUpgradeEvaluationSite  – Creates a copy of the specified Site Collection and performs an upgrade on that copy.
    • Get-SPOWebTemplate – Get a list of all available web templates.
  • Tenants
    • Get-SPOTenant – Retrieves information about the subscription tenant. This includes the Storage Quota size, Storage Quota Allocated (used), Resource Quota size, Resource Quota Allocated (used), Compatibility Range (14-14, 14-15, or 15-15), whether External Services are enabled, and the No Access Redirect URL.
    • Get-SPOTenantLogEntry – Retrieves company logs (as of B2 only BCS logs are available).
    • Get-SPOTenantLogLastAvailableTimeInUtc – Returns the time when the logs are collected.
    • Set-SPOTenant – Sets the Minimum and Maximum Compatibility Level, whether External Services are enabled, and the No Access Redirect URL.
  • Apps
  • Connections

O365 – SharePoint Online: Alpaca JS based Apps development


This article is primarily intended for creating a simple Apps based on Alpaca JS framework for O365 SharePoint Online.

Alpaca Demo

Download Source Code

Click here for Source code 

What is Alpaca JS framework?

Alpaca provides the easiest way to generate interactive HTML5 forms for web and mobile applications. It uses JSON Schema and simple Handlebars templates to generate great looking user interfaces on top of Twitter Bootstrap, jQuery UI, jQuery Mobile and HTML5.

Everything you need is provided out of the box. Alpaca comes pre-stocked with a large library of controls, templates, layouts and features to make rendering JSON-driven forms easy. It is designed around an extensible object-oriented pattern, allowing you to implement new controls, templates, I18N bundles and custom data persistence for your projects.

Alpaca is open-source and provided to you under the Apache 2.0 license. It is supported by Cloud CMS and is in use by organizations and within projects all around the world.

Steps to create the Alpaca based Apps for SharePoint Online

Step I

Create the HTML file by using the below source code,

<!DOCTYPE html>

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;


<title>User Details</title>
<meta charset=”utf-8″ />
<!– alpaca –>
<link type=”text/css” href=”http://code.cloudcms.com/alpaca/1.5.17/bootstrap/alpaca.min.css&#8221; rel=”stylesheet” />

form {
padding-left: 2%;
width: 60%;

$(function () {
“schema”: {
“title”: “User Details”,
“description”: “Fill User Details”,
“type”: “object”,
“properties”: {
“Name”: {
“type”: “string”,
“title”: “Name”,
“id”: “txtName”,
“required”: true
“Password”: {
“type”: “string”,
“title”: “Password”,
“format”: “password”,
“required”: true
“Email Address”: {
“type”: “string”,
“title”: “Email Address”,
“format”: “email”,
“required”: true
“Cell Number”: {
“type”: “number”,
“title”: “Cell Number”,
“maxLength”: 10,
“minLength”: 10,
“required”: true
“options”: {
“form”: {
“attributes”: {
“action”: “http://httpbin.org/post&#8221;,
“method”: “post”
“buttons”: {
“submit”: {
“click”: function () {
this.ajaxSubmit().done(function () {
url: “”,
type: “”,
dataType: “json”
alert(” User Name : ” + $(‘[name=”Name”]’)[0].value + “\n Email Address : ” + $(‘[name=”Email Address”]’)[0].value + “\n Cell Number : ” + $(‘[name=”Cell Number”]’)[0].value);


<link type=”text/css” href=”http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css&#8221; rel=”stylesheet” />



Step II

Click here for: Step by step creating Content Editor webpart and associate with HTML

Step III

Final result will be as below,

Alpaca Demo

O365 -SharePoint Online: step by step creating Content Editor webpart and associate with HTML


For creating content editor webpart by using HTML is common requirement for SharePoint. Here we are covering the steps of achieving the same for O365 SharePoint online.
Alpaca Demo

Download user guide

Click here to download steps by step guide

Step by step approach

Step I

Go the site where to create Content Editor webpart.

Step II

Create Asset Library or Document Library for repository of HTML, CSS, JS etc. resources related to specific Content Type webpart.

Step III

Create folder for Uploading your files of step II with same name of webpart.

Step IV


Step V

Upload the source files,

Step VI

Edit the page where you want to add webpart using below steps,

Step VII

Edit the properties of Content Editor webpart which have been added using step V,


Copy the html path from step V to the properties as below,

Step IX

Now your webpart is ready with HTML loaded,
Alpaca Demo