Adding list items using powershell sharepoint 2010

A simple example of a powershell script to add items in a list in SharePoint 2010. For Add, Update, delete list items with powershell see my post Add,Update,Delete List items using powershell sharepoint 2010

$spAssignment = Start-SPAssignment
$mylist = (Get-SPWeb -identity http://SP -AssignmentCollection $spAssignment).Lists["listName"]
$newItem = $mylist .Items.Add()
$newItem["Title"] = “Added by Powershell”
$newItem["description"] = “My PowerShell Magic”
$newItem.Update()
Stop-SPAssignment $spAssignment

In the example we use the Start-SPAssignment and Stop-SPAssignment cmdlets to make sure that the objects are disposed correctly. Also note that we assign Get-SPWeb to the assignment. We then use the Add() method to create a new item in SharePoint 2010.

Speak Your Mind

*

Disclaimer: The contents of this site are provided “AS IS”. Information and views expressed including URL(s) and other Internet website references, may change without notice. You bear the risk of using it. SharePoint, MOSS, SharePoint 2010, SharePoint 2013 and Microsoft are trademarks of the Microsoft Corporation.Learning SharePoint only provides Tips,Tricks and Tutorials for using Microsoft SharePoint, Microsoft Office and related Softwares.
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.