我正在编写一个连接到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对象困住了,我找不到办法,现在,我只想显示我的列表项目。
谢谢!
答案 0 :(得分:8)
以下示例演示了如何使用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()