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


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

  5. BestCarin says:

    I have noticed you don’t monetize your page, don’t waste your traffic, you can earn extra cash every month.
    You can use the best adsense alternative for any type of
    website (they approve all websites), for more details simply search in gooogle:
    boorfe’s tips monetize your website

  6. mike says:

    Do you have an example that uses PostRequest for placing a file into SharePoint?

  7. Anonymous says:

    Very nice.Thanks!.

  8. Rohit says:

    Thanks Pranav for this nice article on SharePoint 2013.

    I want to make a post call on SharePoint Online and the Multi-Factor Authentication is enabled. I am not able to figure out how do I connect to sharepoint using “Invoke-RestMethod” method.

    Could you please suggest me.

  9. Nell Pridham says:

    Good day!

    You Need Leads, Sales, Conversions, Traffic for pranavsharma.com ?
    I Will Findet…

    Don’t believe me? Since you’re reading this message then you’re living proof that contact form advertising works!
    We can send your ad to people via their Website Contact Form.


    IF YOU ARE INTERESTED, Contact us => lisaf2zw526@gmail.com


  10. DataTraveler says:

    Thanks a lot for posting this working example

Leave a Reply

Your email address will not be published.

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