Monday, March 14, 2011

Blog Post: Sharepoint adding list items with Powershell

$SITE = "MYSERVERNAMEHERE/Lists"
$URI = "
http://$SITE/_vti_bin/lists.asmx"
$listname = "TestMe"

$SPService = New-WebServiceProxy -uri $uri -NameSpace SpWs -UseDefaultCredential
$ListInfo = $SPservice.GetListandView($listname,"")
$ListID  = $ListInfo.List.Name
$ViewID  = $ListInfo.View.Name

# build the XML 'batch' of entries that make up the Item
$doc = new-object "System.Xml.XmlDocument"
$batch = $doc.CreateElement("Batch")
$batch.SetAttribute("OnError", "Continue");
$batch.SetAttribute("ListVersion", "1");
$batch.SetAttribute("ViewName", $ViewID);
$batch.InnerXml = "<Method ID='1' Cmd='New'>" + "<Field Name='Title'>A New Item!</Field>" + "</Method>"

$response = $SPservice.UpdateListItems($ListID, $batch)

Lori Heuring Nicole Scherzinger Jill Arrington Tami Donaldson Padma Lakshmi

No comments:

Post a Comment