SharePoint Online: Get All Lists using PowerShell
Requirement: SharePoint Online Get All Lists inventory using PowerShell
Get All Lists in SharePoint Online using PowerShell CSOM:
Here is the PowerShell to get all lists in a SharePoint Online Site.
How to Get a List in SharePoint Online using PowerShell?
To Get a List in SharePoint Online, use:
PnP PowerShell to Get All Lists from SharePoint Online Site:
Similarly, to get a specific list in SharePoint Online using PnP PowerShell, use:
Get All Lists in SharePoint Online using PowerShell CSOM:
Here is the PowerShell to get all lists in a SharePoint Online Site.
#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" #Function to Get all/specific list from site Function Get-SPOList() { Param ( [Parameter(Mandatory=$true)] [Microsoft.SharePoint.Client.Web] $Web, [Parameter(Mandatory=$false)] [string] $ListName ) #Get the Context $Ctx = $Web.Context #Get a single list or All Lists If($ListName) { #sharepoint online get list powershell $List = $Web.Lists.GetByTitle($ListName) $Ctx.Load($List) $Ctx.ExecuteQuery() Return $List } Else { #sharepoint online get all lists powershell $Lists = $Web.Lists $Ctx.Load($Lists) $Ctx.ExecuteQuery() Return $Lists } } #Parameters $SiteURL="https://crescenttech.sharepoint.com" #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 #sharepoint online powershell get all lists $Lists = Get-SPOList -Web $Ctx.Web #Extract List data $ListCollection = @() ForEach($List in $Lists) { $ListData = New-Object -TypeName PSObject $ListData | Add-Member -MemberType NoteProperty -Name "Title" -Value $List.Title $ListData | Add-Member -MemberType NoteProperty -Name "Itemcount" -Value $List.Itemcount $ListData | Add-Member -MemberType NoteProperty -Name "BaseTemplate" -Value $List.BaseTemplate $ListData | Add-Member -MemberType NoteProperty -Name "Created" -Value $List.Created $ListData | Add-Member -MemberType NoteProperty -Name "LastItemModifiedDate" -Value $List.LastItemModifiedDate $ListCollection += $ListData } #Export List Inventory to CSV $ListCollection | Export-csv -Path "C:\Temp\list-inventory.csv" -NoTypeInformationThis PowerShell gets either a single list or all lists from SharePoint Online site based on the given parameters.
How to Get a List in SharePoint Online using PowerShell?
To Get a List in SharePoint Online, use:
#Call the function to get a List $List = Get-SPOList -web $ctx.Web -ListName "Documents" Write-host "Total Number of Items in List:" $List.ItemCount
PnP PowerShell to Get All Lists from SharePoint Online Site:
#Config Variables $SiteURL = "https://crescenttech.sharepoint.com/" #Connect to PnP Online Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential) #Get all lists $Lists = Get-PnPList #Get List Title, Description and Number of Items $Lists | Select Title, Description, ItemCount
Similarly, to get a specific list in SharePoint Online using PnP PowerShell, use:
#Connect to PNP Online Connect-PnPOnline -Url "https://crescenttech.sharepoint.com" -Credentials (Get-Credential) #Get the List $List = Get-PnPList -Identity "Documents" #Get Number of Items in the List Write-host "Total Number of List Items:"$List.ItemCount
No comments:
Please Login and comment to get your questions answered!