Sharepoint Powershell update Peoplepicker in List

%3CLINGO-SUB%20id%3D%22lingo-sub-1520946%22%20slang%3D%22en-US%22%3ESharepoint%20Powershell%20update%20Peoplepicker%20in%20List%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1520946%22%20slang%3D%22en-US%22%3E%3CP%3EHello%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20run%20a%20script%20that%20reads%20a%20csv%20and%20updates%20peoplepicker.%3C%2FP%3E%3CP%3EMy%20code%20looks%20like%3A%3C%2FP%3E%3CH1%20id%3D%22toc-hId-496857400%22%20id%3D%22toc-hId-496857432%22%3ERead%20the%20CSV%20file%3C%2FH1%3E%3CP%3E%24delimitercsv%20%3D%20%22%7C%22%20%24filePath%20%3D%20%22File.csv%22%20%24CSVData%20%3D%20Import-CSV%20-path%20%24filepath%20-Delimiter%20%24delimitercsv%3C%2FP%3E%3CH1%20id%3D%22toc-hId--1310597063%22%20id%3D%22toc-hId--1310597031%22%3ESharePoint%20column%20names%3C%2FH1%3E%3CP%3E%24costcenter%20%3D%20%22costcenter%22%3C%2FP%3E%3CP%3E%24userid%20%3D%20%22User%20ID%22%3C%2FP%3E%3CP%3E%24useremailowner%20%3D%20%22Owner%22%3C%2FP%3E%3CH1%20id%3D%22toc-hId-1176915770%22%20id%3D%22toc-hId-1176915802%22%3EGet%20the%20SharePoint%20List%3C%2FH1%3E%3CP%3E%24websitedirectory%20%3D%20Get-SPWeb%20-identity%20%22website%22%20%24list%20%3D%20%24websitedirectory.Lists%5B%22Site%20Directory%22%5D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23Iterate%20through%20each%20row%20in%20the%20CSV%20and%20update%20the%20Owner%20Email%3C%2FP%3E%3CP%3E%24items%20%3D%20%24list.Items%3C%2FP%3E%3CPRE%3E%3CSPAN%20class%3D%22kwd%22%3Eforeach%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%24item%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd%22%3Ein%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%24items%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%7C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22kwd%22%3Eget%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E-%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3Emember%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E-%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3EMemberType%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%E2%80%98%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3ENoteProperty%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%E2%80%99%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%7C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22typ%22%3ESelect%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E-%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3EObject%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E-%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3EExpandProperty%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%E2%80%98%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3EName%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%E2%80%99)%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22pun%22%3E%7B%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%20%20%20%20%20%20%20%0A%20%20%20%20%24userid%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%24item%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%5B%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E'User%20ID'%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%5D%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%20%20%20%24useridtest%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%24userid%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E-%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3Ereplace%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E%22.*%23%22%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22pun%22%3E%5B%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3EMicrosoft%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3ESharePoint%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3ESPUser%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%5D%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%24useremail%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%24CSVData%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%7C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22typ%22%3EWhere%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E-%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3EObject%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%7B%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%24_%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3EUsID%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E-%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3Eeq%26nbsp%3B%24userid%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%7D%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%7C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%25%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3EUsID%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%20%20%20%24item%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%5B%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%24useremailowner%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%5D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20domain%5C%24userid%0A%20%20%20%20%24item%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3EUpdate%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E()%3B%3C%2FSPAN%3E%0A%20%20%20%20%0A%20%3CSPAN%20class%3D%22pun%22%3E%7D%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3EUnfortunately%20it%20does%20not%20work.%3C%2FP%3E%3CP%3EDo%20you%20have%20any%20idea%3F%3C%2FP%3E%3CP%3ERegards%20and%20big%20thanks%3C%2FP%3E%3CP%3EJFM_12%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1520946%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Server%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
Occasional Contributor

Hello

 

I want to run a script that reads a csv and updates peoplepicker.

My code looks like:

Read the CSV file

$delimitercsv = "|" $filePath = "File.csv" $CSVData = Import-CSV -path $filepath -Delimiter $delimitercsv

SharePoint column names

$costcenter = "costcenter"

$userid = "User ID"

$useremailowner = "Owner"

Get the SharePoint List

$websitedirectory = Get-SPWeb -identity "website" $list = $websitedirectory.Lists["Site Directory"]

 

#Iterate through each row in the CSV and update the Owner Email

$items = $list.Items

foreach($item in $items | get-member -MemberType NoteProperty | Select-Object -ExpandProperty Name’)
{        
    $userid = $item['User ID']    $useridtest = $userid -replace ".*#"
    [Microsoft.SharePoint.SPUser]$useremail = $CSVData | Where-Object {$_.UsID -eq $userid} | % UsID    $item[$useremailowner] = domain\$userid
    $item.Update();
    
 }

Unfortunately it does not work.

Do you have any idea?

Regards and big thanks

JFM_12

0 Replies