Working with folders and files via SharePoint 2013 REST in PowerShell


In the previous post we’ve already discussed how to perform CRUD operations by sending HTTPS requests to SharePoint RESTful web services in PoweShell. The Invoke-RestSPO function was introduced for that purpose since  Invoke-RestMethod cmdlet does not support claims based authentication and it makes this cmdlet impossible to use in O365 and SharePoint Online scenarios.

This time I am going to demonstrate how  to perform basic create, read, update, and delete (CRUD) operations on folders and files with the SharePoint 2013 REST interface using Invoke-RestSPO function.

Explore the REST service files and folder syntax

SharePoint 20123 Files and Folders REST syntax


Working with folders

Folder resource: represents a folder on a SharePoint Web site

Endpoint URI: http://<site url>/_api/web/getfolderbyserverrelativeurl(‘/<folder name>‘)

Supported HTTP methods:  GET  |  POST  |  DELETE  |  MERGE  |  PUT

The following examples demonstrates how to perform basic CRUD operations with Folder resource.



Working with files

Folder resource: represents a file in a SharePoint Web site that can be a Web Part Page, an item in a document library, or a file in a folder.

Endpoint URI: http://<site url>/_api/web/getfilebyserverrelativeurl(‘/<folder name>/<file name>‘)

Supported HTTP methods:  GET  |  DELETE  |  POST  (File resource)

The following examples demonstrates how to perform basic operations with File resource including:

  • upload file into SharePoint
  • download  file from a SharePoint



To summarize, it was demonstrates how to perform basic operations with files and folders, in particular how to  download and upload files via REST. For that purpose we  utilized Invoke-RestSPO function  that is intended for sending HTTPS requests to O365/SharePoint Online REST service.


7 thoughts on “Working with folders and files via SharePoint 2013 REST in PowerShell

  1. Hi, thanks for the scripts.

    I am trying to upload a file(s) to our sharepoint online site using the Upload-SPOFile function but get an error:

    The process cannot access the file….because it is being used by another process.

    I can’t figure out what that process would be as nothing is open locking that file that I am aware of…it’s just a word doc by itself in a folder.

    Appreciate your help and time.

  2. Hi, ignore my last comment…I have got the file unlocked that I was trying to upload.

    Other question I have though is being able to check in the file…I have it uploading fine to SharePoint Online…but it leaves the file checked out….do you have code examples of how to check in the file using Rest in PowerShell?

  3. Sorry…here is the error…The Remote Server returned an error (401) Unauthorized…

    Am I missing a step that I need to use a token somewhere….don’t see that in the code…but see some of that in your other posts.

  4. Great stuff – but how do I call Download File if I’ve got an item result?



    • Greetings,

      probably you are looking for the following request:


      which will return file content of associated list item.

      • Unfortunately my HTTP Header to download the binary is ignored… I think I’ll just try the file URL directly/traditional download instead.

Leave a Reply to Dion Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.