Use PowerShell to Access ListItems via SharePont 2013 REST


#Function to access SharePoint List Items via REST

function Get-ListItemsREST

{

param($siteurl, $listName);

$url = ($siteurl + "/_api/web/lists/getByTitle('" + $listName + "')/items");


$cookies = New-Object System.Net.CookieContainer;

$request = [System.Net.WebRequest]::Create($url);

$request.Method="GET";

$request.CookieContainer = $cookie;


#this header was what I had been missing for on premises authentication

$request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED","f");


$request.UseDefaultCredentials=$true;


$response=$request.GetResponse();

$stream = New-Object System.IO.StreamReader($response.GetResponseStream());

$responsestring = $stream.ReadToEnd();


[xml]$xmlresponse = $responsestring;


return $xmlresponse.feed.entry;


}


#SAMPLE USAGE

$listitems = Get-ServerList -siteurl "https://spsiteurl/" -listName "Announcements"


foreach ($item in $listitems)

{


    $item.content.Properties;

  

}


Comments

Popular posts from this blog

How To use ASPNET_SetReg to store encrypted data in the registry and then decrypt the data for use in your app

Nostalgia for SNL's Il Returno De Hercules

PowerShell Script to Clean the Windows Installer Directory