Apr 24 2020 03:02 PM - edited Apr 24 2020 04:22 PM
Hello all,
I have done a lot of reading and can't seem to find the answer. I am working on my first PnP script to pull all the data from a SharePoint site and save it into an CSV file. So far everything is working but one thing.
I can not get the "Author" column to save correctly. I assume it is because this data is a "Table" technically, instead of a record, but I am not sure how to specify what I want to return.
Here is a demo code I am working with.
Connect-PnPOnline -Url "MYSITE -UseWebLogin
(Get-PnPListItem -List "MYLIST" -Id 521 -Fields "Author").FieldValues
This returns
Key Value
--- -----
Author Microsoft.SharePoint.Client.FieldUserValue
Any idea how I get it to return the .Email of the user?
EDIT: So I found that if I use
$listItem["Author"].LookupValue
I can get the lookup value of the column, however, I can not figure out how to get this into my Hashtable.
$obj=New-Object PSObject
$listItem.GetEnumerator() | Where-Object { $_.Key -in $Global:selectProperties }| ForEach-Object{ $obj | Add-Member Noteproperty $_.Key $_.Value }
$hashTable+=$obj;
$obj=$null;
Apr 25 2020 06:54 AM
May 21 2021 11:14 AM
I was able to get Microsoft.SharePoint.Client.FieldUserValue to return using the below function
(written by Justin W Grote, provided via the PowerShell Discord):
# provided by @justinwgrote, PowerShell Discord
function ExpandSharepointLookupValue ($Value) {
if ($Value -is [Microsoft.SharePoint.Client.FieldLookupValue]) {
$Value[0].LookupValue
} else {
$Value
}
}
I then adjusted the Add-Member call in the loop to this:
$obj | Add-Member -MemberType NoteProperty -Name $_.Key -Value (ExpandSharepointLookupValue($_.Value))