简体   繁体   English

如何使用PowerShell从Sharepoint Online列表中获取项目?

[英]How to get items from a Sharepoint Online list using PowerShell?

I'm writing a PowerShell script that connects to a SharePoint website and I'm trying to get the items on a list. 我正在编写一个连接到SharePoint网站的PowerShell脚本,我正在尝试将这些项目放在列表中。 Here's my code: 这是我的代码:

$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)

$SitePassword = ConvertTo-SecureString $SitePwd -AsPlainText -Force
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($SiteUser,$SitePassword)
$Context.Credentials = $Creds

$web = $Context.Web 
$Context.Load($web)
$Context.ExecuteQuery()

$List = $Context.Web.Lists.GetByTitle('Déposes')
$Context.Load($List)
$Context.ExecuteQuery()

But now I'm stuck with this $List Object and I can't find a way through. 但是现在我被这个$List对象困住了,我无法找到解决方法。 For now, I just want to display my list's items. 现在,我只想显示我的列表项目。

The following example demonstrates how to retrieve list items using the SharePoint CSOM API in PowerShell: 以下示例演示如何使用PowerShell中的SharePoint CSOM API检索列表项:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")


Function Get-SPOContext([string]$Url,[string]$UserName,[string]$Password)
{
    $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
    $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
    return $context
}

Function Get-ListItems([Microsoft.SharePoint.Client.ClientContext]$Context, [String]$ListTitle) {
    $list = $Context.Web.Lists.GetByTitle($listTitle)
    $qry = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()
    $items = $list.GetItems($qry)
    $Context.Load($items)
    $Context.ExecuteQuery()
    return $items 
}



$UserName = "jdoe@contoso.onmicrosoft.com"
$Password = Read-Host -Prompt "Enter the password"    
$Url = "https://contoso.sharepoint.com/"


$context = Get-SPOContext -Url $Url -UserName $UserName -Password $Password
$items = Get-ListItems -Context $context -ListTitle "Tasks" 
foreach($item in $items)
{
   #...
}
$context.Dispose()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Powershell使用CSOM API从Sharepoint在线获取列表项 - Powershell get list items from Sharepoint online using CSOM API 如何使用 pnp powershell 获取 SharePoint 在线列表中最后修改项目的项目 ID? - How to get item ID of the last modified item in the SharePoint online list using pnp powershell? 如何使用 PowerShell 从 SharePoint 获取所有文档的列表? - How to get a list of all documents from SharePoint using PowerShell? 如何使用Powershell从SharePoint Online文档库中的文档获取“复制链接” - How can I get the “Copy Link” from a document on SharePoint Online document library using Powershell 从 SharePoint Online 列表中删除所有项目 - Delete all items from SharePoint Online list 使用PowerShell从SharePoint Online提取附件 - Extracting attachments from SharePoint online using PowerShell 在SharePoint中使用PowerShell从文档库中获取项目列表 - Getting a list of items from document library using PowerShell in SharePoint 使用 Powershell PNP 获取 Sharepoint 在线文档库中特定文件夹中的项目 - Get items in specific folder in Sharepoint online document library with Powershell PNP 使用 powershell 更新 Sharepoint 所有列表项 - Update Sharepoint All list items using powershell 通过PowerShell在Sharepoint Online中获取任务列表中的更改 - Get changes in a Task List in Sharepoint Online through PowerShell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM