Getting Started with Office 365 and the Client Side Object Model – CSOM

SharePoint 2013 included some huge improvements to the Client Side Object Model, as more and more of the customers that I work with are moving to Office 365 I need to start thinking about updating the various scripts that I have to use CSOM. This is critical as my collection of scripts have been exclusively been written to make use of the Server Object Model - which I'm never, ever going to be able to access in Office 365 🙂

The beauty of CSOM is that the scripts can be run remotely, as long as you have sufficient permissions to the SharePoint site these can be run from your local machine!

One of the pre-requisites of using the CSOM is the SharePoint 2013 client side assemblies which need to be installed on the machine that is running the script, these are included in the SharePoint Server 2013 Client Components SDK which can be downloaded from here -

To get me started, I've written a super-basic script that connects to a Site within an Office 365 tenant and updates the Title and Description - that is all! As I become more proficient with CSOM, I will share my learning with the Blog. The script will prompt for the username and password, all you need to do is update the URL and the Title and Description (highlighted) to get this to work!

#Add references to SharePoint client assemblies and authenticate to Office 365 site
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
$Username = Read-Host -Prompt "Please enter your username"
$Password = Read-Host -Prompt "Please enter your password" -AsSecureString
$Site = ""
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($Site)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username,$Password)
$Context.Credentials = $Creds

#Connect to site within the tenant and update the title and description
$Web = $Context.Web
$Web.Title = "New Title"
$Web.Description = "New Description"

 Brendan Griffin


Comments (3)

  1. shilpa says:

    Simple yet good.. I am trying to learn CSOM and i wasnot knowing that thru powershell we can access client context. Thanks 🙂

  2. vijay says:

    Its awesome article

Skip to main content