I am trying to retrieve the value of a lookup field type from a library in SharePoint Online. I am using the PnP PowerShell Framework, having downloaded the March 2018 release from GitHub (https://github.com/SharePoint/PnP-PowerShell/releases).
I reviewed the following posts, and have tried various combinations of the answers provided therein:
- Fetch Username from Lookup-Column using Powershell
- SharePoint online list get value lookup field with PowerShell
- Fetch Username from Lookup-Column using Powershell-PNP
I've included the entire script here in case there's something more fundamental I've missed elsewhere:
$policy = Get-ExecutionPolicy
if($policy -ne "RemoteSigned"){
Set-ExecutionPolicy unrestricted
}
$url = "https://company.sharepoint.com/sites/sitename"
$listTitle = "A&B Library Title"
Connect-PnPOnline -Url $url -UseWebLogin
$list = Get-PnPList -Identity $listTitle
$items = Get-PnPListItem -List $listTitle
foreach ($item in $items)
{
$itemTitle = $item.FieldValues.FileLeafRef
$lookup = [Microsoft.SharePoint.Client.FieldLookupValue]$item.FieldValues["A&B Column"]
write-host "$itemTitle, lookupValue - $($lookup.LookupValue)"
}
No errors are returned, but the values are all returned blank. For example, despite the fact that ABC.docx, 123.xlsx, and A53.docx all have values in the A&B Column, the output displays as follows:
ABC.docx, lookupValue -
123.xlsx, lookupValue -
A53.docx, lookupValue -
I also wanted to highlight that both the library name and the column name have ampersands in them. This doesn't seem to be an issue for the library title, but I'm not sure if that's what may be preventing the script from returning values from the lookup column. I've tried using both the internal and display names for the column, to no avail.
Thank you in advance!