PowerShell has a great built-in commandlet to call REST methods called Invoke-RestMethod. However, it might take some tinkering to get it working against the SharePoint RESP API. Here is a sample script that will first get the form digest and then pass it in the header of subsequent requests. As an example, this script will create a folder in the specified document library-

Note that this script only calls the POST method during the folder creation example. A GET method is also specified in this script which will come in handy for other types of operations where information is being read from SharePoint. Depending on the task, a MERGE or DELETE method may also be required and can be declared exactly the same way as the GET/POST methods.

For further reference, here is the SharePoint REST API documentation: http://msdn.microsoft.com/en-us/library/office/jj860569(v=office.15).aspx

 

4 Responses to Use PowerShell’s Invoke-RestMethod with the SharePoint 2013 REST API

  1. Greg Tate says:

    This was lifesaver…The example was a great help in getting me down the right path on using REST to upload a file. Thanks!

  2. leigh says:

    Great script.

    But please use write-debug rather than write-hos with the checkt, and please note that Jeffrey Snover says anytime you use write-host, a kitten dies.

  3. Anonymous says:

    Great job!!! I try to add a finction to update list item but it’s too difficult for me now…If someone has an idea?

  4. Christoph Mülder says:

    Thanks a lot for this. Needed some time to get it right but then I have been able to achieve what I wanted with the help of your functions.

Leave a Reply

Your email address will not be published.

Set your Twitter account name in your settings to use the TwitterBar Section.