Shared Points

items of some interest

SharePoint - adding list items with Powershell

SharePoint - adding list items with Powershell

  • Comments 1
  • Likes

# 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.'

$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)

Comments
  • <p>you are doing through web services, any alternate way??</p>

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment