SharePoint – adding list items with Powershell

# I was asked the question 'how can I automatically add items to a List on a
Sharepoint box I cannot access locally? No, not possible to use direct
 sharepoint cmdlets and do not know if it is 2007 or 2010.'

$URI = "
$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)

Comments (1)
  1. you are doing through web services, any alternate way??

Comments are closed.

Skip to main content