How to Add New List Item in SharePoint using PowerShell?

My PowerShell scripts to add list item in SharePoint:

Add SharePoint list items using PowerShell
The syntax to add new list item in SharePoint using PowerShell, goes like this
#Get Web and List Objects
$Web = Get-SPWeb "http://sharepointsite.com"
$List = $Web.Lists["ListName"]

#Create a new item
$NewItem = $List.AddItem()
 
#Set Column values
$NewItem["ColumnName"] = "Field Value goes here!"
 
#Update the Item, so that it gets saved to the list
$NewItem.Update()

Add list item in SharePoint with PowerShell

Lets add new task to the task list using PowerShell: 
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Processing Variables
$WebURL="http://sharepoint.crescent.com"
$ListName="Tasks"

#Get Web and List Objects
$Web = Get-SPWeb $WebURL
$TaskList = $Web.Lists[$ListName]

#Create New Task Item
$NewTask = $TaskList.AddItem()
$NewTask["Title"] = "Migration Project - SOW"

#Add Date Time values
$NewTask["StartDate"] ="02/22/2015 00:00:00"
$NewTask["DueDate"] = "02/25/2015 02:00:00 PM"

#Add Assigned to People Picker field
$NewTask["AssignedTo"] = $Web.EnsureUser("Crescent\Salaudeen")

$NewTask.Update()

Result:
add sharepoint list items using powershell

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.