SharePoint PnP Author column with PowerShell

Copper Contributor

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;

2 Replies
Hi,
To retrieve the Email of the Author, you could run this command $listItem["Author"].Email which will return you the email of the corresponding item creator.

Hope this helps.
Thanks.

@fodelement 

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))