Friday, October 6, 2017

Get start with SPO management shell using CSOM

      1.       Download SharePoint Server 2016 Client Components SDK at this link:

      2.       Install it, it should be appeared at below:

      3.       Open your SharePoint site and create list “Leave Request”

      4.       Open SharePoint Online Management Shell

      5.       Enter the command then input your password:
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" 
$siteURL = "" 
$userId = "" 
$pwd = Read-Host -Prompt "Enter password" -AsSecureString 

      6.       Continue enter the command to display ID and title of list
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, $pwd) 
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL) 
$ctx.credentials = $credentials 
    $lists = $ctx.web.Lists 
    $list = $lists.GetByTitle("Leave Request") 
    $listItems = $list.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()) 
    foreach($listItem in $listItems) 
        Write-Host "ID - " $listItem["ID"] "Title - " $listItem["Title"] 
    write-host "$($_.Exception.Message)" -foregroundcolor red 

      7.       Finished


Post a Comment