what List item data can be gotton from SharePoint getItems() method?

167 Views Asked by At

in the output from rest API: https://graph.microsoft.com/beta/sites//lists//items, I can get the Listitem value like this:

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

I want to get these item data for each List item, but in below foreach code, I only can get item's title and 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
            }

If I write $item["webUrl"], will get empty value. How can get others list item data in powershell?

1

There are 1 best solutions below

0
Lee On

You could use PnP PowerShell for this easily.

#region Variables 
$Username = "[email protected]" 
$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 "----------"