Compartilhar via


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

$SITE = "MYSERVERNAMEHERE/Lists"
$URI = "https://$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

  • Anonymous
    January 01, 2003
    you are doing through web services, any alternate way??