SharePoint Online: Get List by Title using PowerShell
Requirement: PowerShell to get a list by title in SharePoint Online
SharePoint Online: PowerShell to Get List by Title
In this blog post, we will go over how to get a list by title in SharePoint Online using PowerShell. 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
$SiteURL="https://Crescent.sharepoint.com"
$ListName="Documents"
#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
$List=$Ctx.Web.Lists.GetByTitle($ListName)
$Ctx.load($List)
$Ctx.ExecuteQuery()
Write-host "Total Number of List Items:"$List.ItemCount
PnP PowerShell to Get a List by Its Title
If you’re looking for a quick way to get a list by its Title in SharePoint Online, Here is the PnP PowerShell to get a list or library from a SharePoint Online site:
#Set Parameters
$SiteURL="https://Crescent.sharepoint.com/sites/marketing"
$ListName= "Projects"
#Connect to SharePoint Online
Connect-PnPOnline -url $SiteURL -Interactive
#Get the List by its Title
$List = Get-PnPList -Identity $ListName
Write-host $List.ItemCount