当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:使用 PowerShell 按标题获取列表

作者:精品下载站 日期:2024-12-14 21:07:55 浏览:17 分类:玩电脑

SharePoint Online:使用 PowerShell 按标题获取列表


要求:使用 PowerShell 在 SharePoint Online 中按标题获取列表。

SharePoint Online:PowerShell 按标题获取列表

在 SharePoint Online 中,PowerShell 提供了一种管理 SharePoint 列表和库的强大方法。在 PowerShell 中使用 SharePoint 列表时的一项常见任务是按标题检索列表。在这篇博文中,我们将回顾如何使用 PowerShell 在 SharePoint Online 中按标题获取列表。

以下是如何通过标题获取列表:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\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 按标题获取列表

如果您正在寻找一种在 SharePoint Online 中按标题获取列表的快速方法,可以使用以下 PnP PowerShell 从 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

按照本文中提供的脚本,您可以轻松地按标题检索列表并使用 PowerShell 对其执行操作。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯