SharePoint Online: obtener lista por título usando PowerShell
Requisito: PowerShell para obtener una lista por título en SharePoint Online.
SharePoint Online: PowerShell para obtener lista por título
En SharePoint Online, PowerShell proporciona una forma eficaz de administrar listas y bibliotecas de SharePoint. Una tarea común cuando se trabaja con listas de SharePoint en PowerShell es recuperar una lista por su título. En esta publicación de blog, revisaremos cómo obtener una lista por título en SharePoint Online usando PowerShell.
A continuación se explica cómo obtener una lista por título:
#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 para obtener una lista por título
Si está buscando una forma rápida de obtener una lista por título en SharePoint Online, aquí está el PnP PowerShell para obtener una lista o biblioteca de un sitio de SharePoint Online:
#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
$list | Select-Object Title, Id, BaseTemplate
Write-host $List.ItemCount
Siguiendo los scripts proporcionados en este artículo, puede recuperar fácilmente una lista por su título y realizar operaciones en ella usando PowerShell.