Add list items using powershell sharepoint 2010

A simple example of a powershell script to add items in a list in 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”
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.


Post a Comment


This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at .

Copyright (c) 2010 @ All rights are reserved.Do Not Copy.

@ Learning