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”
$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.
$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.
0 comments:
Post a Comment