0

I'm quite new with both SharePoint and PowerShell so please bear with me. I created a list on SharePoint and I'm trying to get the values of items in this list. For the most part this works ok except for the lookup fields. Whenever I tried to read the values of those fields I get the following value:

Microsoft.SharePoint.Client.FieldLookupValue

This is the code I use:

foreach ($item in $Items) {
$ListItem = [Microsoft.SharePoint.Client.ListItem]$listItem = $List.GetItemById($Item.FieldValues["ID"])
$SPListItemColumns = @{
    Department = "Department"
    }
$Department = $item.FieldValues[$SPListItemColumns.Department] 
}

I tried the code found here, but this returns the following error: Unable to find type [Microsoft.SharePoint.SPFieldLookupValue].

Any help is appreciated, thanks.

1 Answer 1

0

you can use this code to fetch the lookup field values from a list items.

foreach ($listitem in $listItems)  
{
    $lookup = [Microsoft.SharePoint.Client.FieldLookupValue]$listitem.FieldValues["lookup column name"]
    write-host "lookupValue - $($lookup.LookupValue)"
    write-host "lookupId - $($lookup.LookupId)"
}

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.