I'm trying to retrieve information from two columns on a sharepoint list in order to use them in powershell. Here's my code so far:
$SiteURL = "https://xxxx.sharepoint.com/sites/xxxxx/"
#Connect to PNP Online
$creds = Get-AutomationPSCredential -Name "xxxxxxx"
Connect-PnPOnline -Url https://xxxxx-admin.sharepoint.com/ -Credentials $creds
#Get a list by name
$FetchList = Get-PnPList -Identity Lists/xxxxxxx
#sharepoint online pnp powershell get list items
$ListItems = (Get-PnPListItem -List $FetchList -Fields "Host").FieldValues
#Loop through each Item
foreach($ListItem in $ListItems)
{
Write-Host "Title:" $ListItem["Title"]
}
The loop should be printing the values on the column "Host", but it's not printing anything.
And my problem is, the Get-PnPList keeps returning null, meaning I'm getting no output while I'm looping through everything. I've tried using list id, list name, everything and it always returns null. Am I missing something? I'm creating this in an Azure runbook.
I even tried to simply invoke Get-PnPList with no arguments, which according to the documentation for that cmdlet it should return every single available list for that website, but it still returns null (I tried printing the output which should have been a Microsoft.SharePoint.Client.List object, but nothing appears).
I can confirm the $SiteURL is correct because I used powerautomate which auto-completes to the correct URL.
Thank you.