SOLVED

Fill PeoplePicker Field via PnP PowerShell

Brass Contributor

Hey everybody,

 

I have an Excel-List which contains a column which includes email addresses which I want to upload to a SharePoint List with PnP "Add-PnPListItem". 

The addresses are comma-separated (mail@test.com, mail2@test.com  ).

 

My problem is I found no way so far to get the correct syntax. I get the following error: Add-PnPListItem : The specified user mail@test mail2test.com could not be found.

 

I tried inserting the string, creating an object and an array-list and always get the same error. The addresses are correct.

 

My code I use.

 

 $Members = $WorkSheet.Range("G$i").Value2          #PeoplePicker - Input via Email

  #Did not worked
  #$Object = New-Object PSObject 
  #$Object | Add-Member NoteProperty "Members" $Members
            
  #[System.Collections.ArrayList]$MyAL = @()                
  #$Members.Split(",") | ForEach {
  #$MyAL.Add($_)}


Add-PnPListItem -List $listName -Values @{"Title"=$ProjectNo; `
                                              "ProjectNameWithLink"="$ProjectSiteUrl, $ProjectName"; `
                                              "ProjectName"="$ProjectName"; `
                                              "ClientLookup"="$Client"; `
                                              "Manager"="$ProjectManager"; `
                                              "Director"="$Director"; `
                                              "Start"="$StartDate"; `
                                              "End"="$EndDate"; `
                                              "Members" = "$MyAL"
                                               }                     
    }

 

 

How do I get the correct format/type to insert multiple people with Add-PnPListItem?

 

Best regards

 

 

EDIT:


I modified the Data Typ. I now get an Array, and it should be same as when I create it by hand.

$Members = $WorkSheet.Range("G$i").Value2.Split(',').Trim()

However, the problem still exists. I cant add the Members.

1 Reply
best response confirmed by wit4r7 (Brass Contributor)
Solution

@wit4r7 

 

I just want to answer my own question.

 

After getting it into the correct format (the array) I messed up with quotation marks.

 

The following worked for me.

$Members = $WorkSheet.Range("G$i").Value2.Split(';').Trim()      
$Members.Replace('"', '')
Add-PnPListItem -List $listName -Values @{"Members" = $Members}
1 best response

Accepted Solutions
best response confirmed by wit4r7 (Brass Contributor)
Solution

@wit4r7 

 

I just want to answer my own question.

 

After getting it into the correct format (the array) I messed up with quotation marks.

 

The following worked for me.

$Members = $WorkSheet.Range("G$i").Value2.Split(';').Trim()      
$Members.Replace('"', '')
Add-PnPListItem -List $listName -Values @{"Members" = $Members}

View solution in original post