SharePoint Online: Get List by Title using PowerShell

SharePoint Online: PowerShell to Get List by Title

Here is how to get a list by its title.

#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"
#Config Parameters

#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get the List

Write-host "Total Number of List Items:"$List.ItemCount

PnP PowerShell to Get a List by Its Title

#Set Parameters
$ListName= "Projects"

#Connect to SharePoint Online
Connect-PnPOnline -url $SiteURL -UseWebLogin

#Get the List by its Title
$List = Get-PnPList -Identity $ListName
Write-host $List.ItemCount

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!

Leave a Reply