File upload operations are quite frequently used and often tricky when the SharePoint governance allows only SharePoint Client Side Technologies.
Recently I have come across a requirement in one of my assignments where an automated process is required to Sync the network shares with SharePoint.
This provides me the opportunity to write down the automation process using PowerShell +CSOM combination.
In this demo we will explore the PowerShell code to upload the file to SharePoint Online/On Premise Implementations which represents just a part of the complete automation process.
In order to setup this demo I have created as document library in SharePoint Online Site as shown below:



Let’s consider that we have a File Share somewhere on the network having files to be uploaded to the SharePoint Document Library

Now let’s explore the code step by step:
Step 1
In this step Client connection has been setup and the Client Context has been initiated.
The below is representing the connection to SharePoint Online Site but this will be little different in case you want to initiate the connection with SharePoint On Premise site there will be a slight difference in the code.
For details you can visit to my earlier blogs at below URLs,
- https://howtodowithsharepoint.wordpress.com/category/sharepoint-2013/sharepoint-online/
- https://howtodowithsharepoint.wordpress.com/category/powershell-with-csom/

Step 2
In this step we will instantiate the Document Library Object that will provide us the handle on the desired document library in SharePoint Online Site.
This handle will let us allow getting reference of the desired folder in the document library. In this demo we are referring to the Root Folder of the document library
Step 3
In this step we will explore the File System folder by using Get-ChildItem cmdlet on the using the specific Folder path
Step 4
In this step we will call another supporting function to upload the files to SharePoint Document Library








Join the conversation! Your thoughts help the community grow.