Add user in list from csv or excel file using PowerShell

  •  
  •  
  •  
  •  
  •  
  •  

$spAssigment = Start-SPAssignment    #Use to dispose SPWeb safely
$spWeb = Get-SPWeb “http://weburl” -AssignmentCollection $spAssignment     #Get SPWeb Instance
$spList = $spWeb.Lists[“ListName”]    #Get list instance

$testcsv = import-csv C:\user.csv

Write-Host “Start To Add Item”
foreach($test in $testcsv)
{
$spItem = $spList.AddItem()
$spItem[“User”] = $test.UserID # .UserID is column name
$spItem.Update()
# ======================
$UserID = $test.UserID
Echo “User:-$UserID”
}
Write-Host “End To Add Item”

Leave a Reply

Your email address will not be published.

one × 4 =