How to: Upload files into Office 365 via PowerShell

Overview

Being one of the most common questions “How to upload files to SharePoint Library?”, i noticed that usually folder structure is not taken into account in the provided solutions.
So i decided to fill the gap and implement another version that allows to preserve folder structure while uploading files.

Prerequisites

PowerShell script

PowerShell script demonstrates how to upload  files within a specified local directory to a Document Library within a Site in an O365 tenant.

 

Advertisements

15 thoughts on “How to: Upload files into Office 365 via PowerShell

  1. Great script, but don’t forget to close the stream:

    $FileStream = $LocalFile.OpenRead();
    [Microsoft.SharePoint.Client.File]::SaveBinaryDirect($Web.Context, $fileUrl, $FileStream, $true)
    $FileStream.Close();

  2. i tried to use this script but i got an error. it says that “Documents” does not exist. as i have checked, Document library folder exist on my SharePoint account.

    • If your native language is different than English try typing “documents” in your own language that worked for me.

  3. Thanks for the script it’s great. I am trying to figure out how to start the import one level deeper and wonder if had a tip? So not at the root level context but starting at a sub-folder? Thanks!

  4. When i attempt to upload to sharepoint online, I can create the folder structure but no documents will create. I’ve tried running as administrator and normal user, The account I’m using on the sharepoint online is the site owner so doesnt have the required permissions.

  5. I need to do this for a OneDrive migration, but what I want is to create a folder called “Archive” and then copy all the content into that folder so users don’t get cluttered with old content. Any clues? I’m OK with Powershell generally but only just started looking as Sharepoint, CSOM, etc.

    • My workaround at present for this is to move the existing HomeDrive content into a “Archive” folder at the source using standard file operations I understand, but this isn’t ideal.

  6. I am getting error as
    Exception calling “ExecuteQuery” with “0” argument(s): “The sign-in name or password does not match one in the Microsoft account system.”

    But the account do exists.

    The account is working if I login through webportal.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s