Download and Install SharePoint Online Client Components SDK using PowerShell

What is SharePoint Online client components SDK?

The SharePoint Online Client Components SDK provides the tools necessary to develop applications that interact with SharePoint Online. It includes libraries for accessing SharePoint data and functionality and extensive documentation on how to use these libraries. We need SharePoint Online client components SDK installed on the client machine to be able to connect and work with SharePoint Online objects programmatically from the client-side using PowerShell.

Download and Install the SharePoint Online client components SDK

We can download the latest SharePoint Online client components SDK from the Official Microsoft download center at https://www.microsoft.com/en-us/download/details.aspx?id=42038,

install client side SDK for sharepoint online powershell

This installs CSOM assemblies (DLL files – Such as: Microsoft.SharePoint.Client.dll, Microsoft.SharePoint.Client.Runtime.dll, etc.) at folder “C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI”

powershell to install sharepoint online assemblies

Connect to SharePoint Online CSOM from PowerShell

Once installed, you can reference them in your PowerShell scripts as:

#Load SharePoint CSOM 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"

#Get Credentials to connect
$Cred= Get-Credential
$SiteURL = "https://crescent.sharepoint.com"
 
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Get The Web
$Web =  $Ctx.Web
$Ctx.Load($Web)
$Ctx.ExecuteQuery()

#Get Web Title
Write-host $Ctx.Web.Title

Download and Install SharePoint Online Client Components SDK using PowerShell

How about downloading and installing CSOM assemblies using PowerShell? Here is the PowerShell to install SharePoint online client components SDK:

#Parameters
$DownloadURL = "https://download.microsoft.com/download/B/3/D/B3DA6839-B852-41B3-A9DF-0AFA926242F2/sharepointclientcomponents_16-6906-1200_x64-en-us.msi"
$Assemblies= @(
        "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll",
        "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
    )

#Check if all assemblies given in the list are found
$FileExist = $True
ForEach ($File in $Assemblies)
{
    #Check if CSOM Assemblies are Found
    If(!(Test-Path $File))
    {
        $FileExist = $False; Break;
    }
}

#Download and Install CSOM Assemblies
If(!$FileExist)
{
    #Download the SharePoint Online Client SDK
    Write-host "Downloading SharePoint Online Client SDK..." -f Yellow -NoNewline
    $InstallerPath = "$Env:TEMP\SharePointOnlineClientComponents16.msi"
    Invoke-WebRequest $DownloadURL -OutFile $InstallerPath
    Write-host "Done!" -f Green
    
    #Start Installation
    Write-host "Installing SharePoint Online Client SDK..." -f Yellow -NoNewline
    Start-Process MSIExec.exe -ArgumentList "/i $InstallerPath /qb" -Wait
    Write-host "Done!" -f Green
}
Else
{
    Write-host "SharePoint Online CSOM assemblies are already installed!" -f Yellow
}

If you want to uninstall SharePoint online client components SDK, use “Add or Remove Programs” under the control panel!

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

2 thoughts on “Download and Install SharePoint Online Client Components SDK using PowerShell

Leave a Reply