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.

  • Here's the error I'm getting: prnt.sc/wofidg
    – Ress
    Jan 15, 2021 at 11:32
  • 2
    You are connecting to the Admin site instead of the site set in variable $SiteURL. Change it and try again Jan 15, 2021 at 13:35
  • Hi Matiur. I tried in my local Powershell ISE and the code works there, but not in Azure. The only difference is that I used input credentials on my local PS instead of using Get-AutomationPSCredential. But I checked the credential and it's the same one I'm using locally
    – Ress
    Jan 15, 2021 at 14:18

1 Answer 1


Matiur's answer was correct. I was in fact connecting to the tenant/admin page instead of the correctg subpage. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.