jordan
jordan

Reputation: 3546

How to use powershell and the (S)SOM to upload files/directories into sharepoint 2013 in Office365?

I would like to start up a new script, which takes in a Local file path, and a document library name, and then scrapes the directory, and uploads all files/folders found into the sharepoint 2014 office 365 document library (server side object model {SOM}).

I have tried the following, to no success:

  1. http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=487
  2. https://gallery.technet.microsoft.com/office/Copy-all-SharePoint-Files-0999c53f
  3. https://camerondwyer.wordpress.com/2013/05/27/how-to-import-upload-an-entire-folder-of-files-to-sharepoint-using-powershell/

Our tenant is in the could - office 365 We are using sharepoint 2013 We want to be able to look into a folder, and take all documents with folder structure and, via powershell, copy structure and files to our sharepoint tenant.

Upvotes: 1

Views: 2676

Answers (1)

Myles Jeffery
Myles Jeffery

Reputation: 241

The links you have tried are using the SharePoint server object model which only works for SharePoint on-premises. You need the SharePoint client side object model to work with SharePoint Online.

Brendan Griffin posted an article on uploading files to a SharePoint Online document library using the client side object model and PowerShell here: http://blogs.technet.com/b/fromthefield/archive/2014/02/19/office365-script-to-upload-files-to-a-document-library-using-csom.aspx

Here's a key part of the PowerShell code where the SharePoint Online credentials are set on the ClientContext:

#Bind to site collection
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
$Context.Credentials = $Creds

Upvotes: 2

Related Questions