SharePoint PnP Author column with PowerShell

%3CLINGO-SUB%20id%3D%22lingo-sub-1336777%22%20slang%3D%22en-US%22%3ESharePoint%20PnP%20Author%20column%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1336777%22%20slang%3D%22en-US%22%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EHello%20all%2C%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EI%20have%20done%20a%20lot%20of%20reading%20and%20can't%20seem%20to%20find%20the%20answer.%20I%20am%20working%20on%20my%20first%20PnP%20script%20to%20pull%20all%20the%20data%20from%20a%20SharePoint%20site%20and%20save%20it%20into%20an%20CSV%20file.%20So%20far%20everything%20is%20working%20but%20one%20thing.%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EI%20can%20not%20get%20the%20%22Author%22%20column%20to%20save%20correctly.%20I%20assume%20it%20is%20because%20this%20data%20is%20a%20%22Table%22%20technically%2C%20instead%20of%20a%20record%2C%20but%20I%20am%20not%20sure%20how%20to%20specify%20what%20I%20want%20to%20return.%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EHere%20is%20a%20demo%20code%20I%20am%20working%20with.%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EConnect-PnPOnline%20-Url%20%22MYSITE%20-UseWebLogin%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E(Get-PnPListItem%20-List%20%22MYLIST%22%20-Id%20521%20-Fields%20%22Author%22).FieldValues%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EThis%20returns%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EKey%20Value%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E---%20-----%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EAuthor%20Microsoft.SharePoint.Client.FieldUserValue%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EAny%20idea%20how%20I%20get%20it%20to%20return%20the%20.Email%20of%20the%20user%3F%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EEDIT%3A%20So%20I%20found%20that%20if%20I%20use%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%24listItem%5B%22Author%22%5D.LookupValue%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EI%20can%20get%20the%20lookup%20value%20of%20the%20column%2C%20however%2C%20I%20can%20not%20figure%20out%20how%20to%20get%20this%20into%20my%20Hashtable.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%24obj%3DNew-Object%20PSObject%3CBR%20%2F%3E%24listItem.GetEnumerator()%20%7C%20Where-Object%20%7B%20%24_.Key%20-in%20%24Global%3AselectProperties%20%7D%7C%20ForEach-Object%7B%20%24obj%20%7C%20Add-Member%20Noteproperty%20%24_.Key%20%24_.Value%20%7D%3CBR%20%2F%3E%24hashTable%2B%3D%24obj%3B%3CBR%20%2F%3E%24obj%3D%24null%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1336777%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1337551%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20PnP%20Author%20column%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1337551%22%20slang%3D%22en-US%22%3EHi%2C%3CBR%20%2F%3ETo%20retrieve%20the%20Email%20of%20the%20Author%2C%20you%20could%20run%20this%20command%20%24listItem%5B%22Author%22%5D.Email%20which%20will%20return%20you%20the%20email%20of%20the%20corresponding%20item%20creator.%3CBR%20%2F%3E%3CBR%20%2F%3EHope%20this%20helps.%3CBR%20%2F%3EThanks.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2376526%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20PnP%20Author%20column%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2376526%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F380075%22%20target%3D%22_blank%22%3E%40fodelement%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20was%20able%20to%20get%20Microsoft.SharePoint.Client.FieldUserValue%20to%20return%20using%20the%20below%20function%3C%2FP%3E%3CP%3E(written%20by%20Justin%20W%20Grote%2C%20provided%20via%20the%20PowerShell%20Discord)%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23%20provided%20by%20%40justinwgrote%2C%20PowerShell%20Discord%3CBR%20%2F%3Efunction%20ExpandSharepointLookupValue%20(%24Value)%20%7B%3CBR%20%2F%3Eif%20(%24Value%20-is%20%5BMicrosoft.SharePoint.Client.FieldLookupValue%5D)%20%7B%3CBR%20%2F%3E%24Value%5B0%5D.LookupValue%3CBR%20%2F%3E%7D%20else%20%7B%3CBR%20%2F%3E%24Value%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20then%20adjusted%20the%20Add-Member%20call%20in%20the%20loop%20to%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24obj%20%7C%20Add-Member%20-MemberType%20NoteProperty%20-Name%20%24_.Key%20-Value%20(ExpandSharepointLookupValue(%24_.Value))%3C%2FP%3E%3C%2FLINGO-BODY%3E
New 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))