0

在其余 API 的输出中:https ://graph.microsoft.com/beta/sites//lists//items,我可以像这样获得 Listitem 值:

            "@odata.etag": xxx,
            "createdDateTime": xxx,
            "eTag": xxx,
            "id": xx,
            "lastModifiedDateTime": xx,
            "webUrl": xxx,
            "createdBy": {
                "user": {
                    "displayName": "System Account"
                }
            },

我想为每个 List 项目获取这些项目数据,但在下面的 foreach 代码中,我只能获取项目的标题和 ID:

$spqQuery = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()
            $items=$ll.GetItems($spqQuery)
            $ctx.Load($items)
            $ctx.ExecuteQuery()
            foreach($item in $items){
            Write-Host $item["Title"] $item["id"] -f Yellow
            }

如果我写 $item["webUrl"],将得到空值。如何在powershell中获取其他列表项数据?

4

1 回答 1

0

您可以轻松地使用PnP PowerShell

#region Variables 
$Username = "user@xxx.onmicrosoft.com" 
$Password = "Password" 
$siteUrl = "https://xxx.sharepoint.com/sites/lee" 

#endregion Variables

#region Credentials 
[SecureString]$SecurePass = ConvertTo-SecureString $Password -AsPlainText -Force 
[System.Management.Automation.PSCredential]$PSCredentials = New-Object System.Management.Automation.PSCredential($Username, $SecurePass) 
#endregion Credentials

Connect-PNPOnline -Url $siteUrl -Credentials $PSCredentials
$items =(Get-PnPListItem -List TestList -Fields "Title","User","ProjectName").FieldValues
foreach($item in $items) {
Write-Host $item["Title"]"-"$item["User"].Email"-"$item["ProjectName"]
}
Write-Host "----------"
于 2020-02-04T02:11:39.723 回答