$spWeb = Get-SPWeb -identity http://SP
$spList = $spWeb.GetList(“Lists/Announcements")
$newItem = $spList.AddItem()
$newItem["Title"] = "My First Announcement"
$newItem["Body"] = "
PowerShell Magic
"$newItem["Expires"] = "5/5/2010"
$newItem.Update()
$spWeb.Dispose()
In the example we use the Get-SPWeb cmdlet to bind to a specific site. Next we use the GetList() method to retrieve a list. The method accepts a lists relative URL as input. We then use the AddItem() method to create a new item in SharePoint 2010. Finally we use the Dispose() method on the SPWeb object to make sure that the object is disposed of correctly.
No comments:
Post a Comment