0

I'm new with PnPPowershell and trying to work with some data in columns. I'm trying to understand the values in user -- both single and multi user columns. I have this code (all the variables used are defined earlier if not shown, and the code does work.) and it outputs the following

$FieldNames = "ID","Title","SinglePerson","MultiPerson"
$listItems = (Get-PnPListItem -List $ListName -Fields $FieldNames -PageSize 1000).FieldValues

$listItems | ForEach-Object {
    $_.GetEnumerator() | Where-Object { $_.Key -IN $FieldNames } | ForEach-Object {   
        Write-Host $_.Key $_.Value
    }  
}

ID 2
Title Single and multi
SinglePerson Microsoft.SharePoint.Client.FieldUserValue
MultiPerson Microsoft.SharePoint.Client.FieldUserValue Microsoft.SharePoint.Client.FieldUserValue Microsoft.SharePoint.Client.FieldUserValue

I found this documentation which says that there is an Email property. So I can get the email(s) by using $_.Value.Email. But I need to know that it is a person column and not a text or other type of column.

How can I get the value of the SinglePerson and MultiPerson columns? When iterating over all the columns how can I know if I have a single person or multi person column?

This is just a test for learning and eventually I need to iterate over thousands of list items with about 50 columns of various types.

2 Answers 2

0

Maybe you could try CSOM. My test is to display the data of an Item, which can display the email address. Of course, you can also display all the Items in a column by looping. The following is my code, I hope it helps you a little:

#Variables for Processing

$SiteURL = "https://crescent.sharepoint.com/sites/PMO"

$ListName = "Projects"

$ItemID = "1"

 #Get Credentials to connect

$Cred = Get-Credential

 Try {    #Setup the context

    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)

    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

     #Get the List Item

    $List = $Ctx.Web.Lists.GetByTitle($ListName)

    $ListItem = $List.GetItemById($ItemId)

   $Ctx.Load($ListItem)    $Ctx.ExecuteQuery()     #Get the "Created By" column value of the Item

    $CreatedBy = $ListItem.FieldValues["Author"]

     #Get the User Object

    $User = $Ctx.Web.GetUserById($CreatedBy.LookupId)

   $Ctx.Load($User)    $Ctx.ExecuteQuery() 

    $User | Select Email, Title, LoginName  

}Catch {

    write-host -f Red "Error:" $_.Exception.Message

}

enter image description here

-1

Maybe you could refer to the following two articles to implement with PowerShell:

Get-Set Person or Group (People Picker) Field Value using PowerShell in SharePoint

SharePoint Online: Read / Update Person or Group Field (People Picker) Values using PowerShell


If the answer is helpful, please click "√" on the left panel of the answer and kindly upvote it.

1
  • When sharing a link to a resource please include a little bit of explanation so that if the link goes dead in the future the answer could still be useful. Additionally, neither of those pages refer to how to tell the type of a column when there are other columns being processed. Also both of those are pretty old.
    – Rothrock
    Jun 10, 2022 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.