gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 09:47:30 26 4
gpt4 key购买 nike

我正在编写一个连接到 SharePoint 网站的 PowerShell 脚本,并且我正在尝试获取列表中的项目。这是我的代码:

$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()

但现在我被这个 $List 对象困住了,我找不到解决办法。现在,我只想显示我的列表项。

最佳答案

以下示例演示如何在 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()

关于powershell - 如何使用 PowerShell 从 Sharepoint Online 列表中获取项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32699338/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com