SharePoint client-side object model (CSOM) module for PowerShell .
PowerShell C#
Clone or download
Latest commit 57643bc Aug 28, 2017
Permalink
Failed to load latest commit information.
doc Updated Index.md Aug 28, 2017
lib Release 0.9 commit Jul 18, 2017
source Modified SPClient.psd1 Aug 28, 2017
.gitattributes Initial commit Jul 18, 2017
.gitignore Release 0.6 commit Jul 18, 2017
LICENSE Initial commit Jul 18, 2017
README.md Modified README.md Aug 17, 2017

README.md

SPClient

PowerShell module for SharePoint client-side object model (CSOM).

Build status License

Features

  • Automatically called ClientContext.Load() method. You do not have to consider call timing, you will be released from "Load hell".
  • String-based (in other words, JSOM-liked) data retrieval expression.
  • Easily debug client objects. You can get loaded properties only.

Prerequisites

Install SharePoint Server 2016 Client Components SDK or SharePoint Server 2013 Client Components SDK in order to use this module.

Installation

SPClient is published to PowerShell Gallery. To install SPClient to your computer run the cmdlet below.

PS> Install-Module -Name SPClient

Functions

See Command Reference.

Getting Started

If you write PowerShell script using the CSOM, it will be like below.

# Load assemblies
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll'

# Create credentials
$userName = 'administrator'
$password = 'password'
$domain = 'domain.local'
$password = ConvertTo-SecureString -String $password -AsPlainText -Force
$credentials = New-Object System.Net.NetworkCredential($userName, $password, $domain)

# Create context
$url = 'http://localhost'
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$clientContext.Credentials = $credentials

# Get web title
$web = $clientContext.Web
$clientContext.Load($web)
$clientContext.ExecuteQuery()
Write-Host $web.Title

# Get all lists 'ServerRelativeUrl'
# You can not use Load method with retrievals!
$lists = $web.Lists
$clientContext.Load($lists)
$clientContext.ExecuteQuery()
$lists | %{ 
    $clientContext.Load($_.RootFolder)
    $clientContext.ExecuteQuery()
    Write-Host $_.RootFolder.ServerRelativeUrl
}

If using SPClient module, it will be like below.

# Load assemblies
Use-SPClientType

# Connect to SharePoint
Connect-SPClientContext -Network `
    -Url 'http://localhost' `
    -UserName 'administrator' `
    -Password (ConvertTo-SecureString -String 'password' -AsPlainText -Force) `
    -Domain 'domain.local'

# Get web title
Get-SPClientWeb -Path Default | %{ Write-Host $_.Title }

# Get all lists 'ServerRelativeUrl'
Get-SPClientWeb -Path Default | Get-SPClientList -Retrieval 'Include(RootFolder.ServerRelativeUrl)' | %{ Write-Host $_.RootFolder.ServerRelativeUrl }