SharePoint Online Automation: O365 SharePoint Online- How to Upload your files remotely using PowerShell to SPO document Library.
Continue, with SharePoint Online Automation Today going to demonstrate about “O365 SharePoint Online- How to Upload your files remotely using PowerShell to SPO document Library”.
In My last below articles, I have described you about below mentioned:
In this article, we will learn about O365 SharePoint Online- How to Upload your files remotely using PowerShell to SPO document Library. It’s very common query and requirement with Admins to Upload the files which are placed in the local system to SharePoint sites to avoid manual tasks, Risks, and hassle-free process.
Let us start live example step by step with screenshots:
- Open PowerShell ISE with Admin rights and copy below script
As mentioned in last articles, we always need to do changes of the defined variable as per your requirement. Here we need to update the below details:
- $User = User Name of your Office 365 account
- $Password = Your Account password
- $Site URL: Site URL of Office 365 SharePoint Online where you want to copy or move document
- $Folder: Destination location from here it will copy your files and copy to destination URL
- $DocLibName: Document Library name where you want to Copy the Files which will take from Local system
#Specify tenant admin and site URL
$User = "Your id"
$Password = 'Your Password'
$SiteURL = "Site URL/"
$Folder = "C:\Script\HpeQuota" #Path where you want to Copy
$DocLibName = "Documents" #Docs library
#Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Bind to site collection
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,(ConvertTo-SecureString $Password -AsPlainText -Force))
$Context.Credentials = $Creds
#Retrieve list
$List = $Context.Web.Lists.GetByTitle($DocLibName)
$Context.Load($List)
$Context.ExecuteQuery()
#Upload file
Foreach ($File in (dir $Folder -File))
{
$FileStream = New-Object IO.FileStream($File.FullName,[System.IO.FileMode]::Open)
$FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
$FileCreationInfo.Overwrite = $true
$FileCreationInfo.ContentStream = $FileStream
$FileCreationInfo.URL = $File
$Upload = $List.RootFolder.Files.Add($FileCreationInfo)
$Context.Load($Upload)
$Context.ExecuteQuery()
}
Save the above script once all changes has been done, In above script, you can see I have added Add-Type -path, which will refer reference file of SharePoint Online Management shell.
We need to follow below steps to execute above command without any error:
- Ensure that SharePoint Client components SDK installed on a user machine if it’s not installed kindly download the same executable file and install to your local system:
- Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll paths mentioned in the script are same as user’s machine
- Set the “execution policies” for PowerShell in user machine by executing Remote signed
Set-ExecutionPolicy Remotesigned
Once you have verified all pre-requisites, you are ready to run the script which will upload your files from local system to SharePoint site URL under a document library. Now click on F5 and wait for some time to get upload all files which is copied from local system to SharePoint Online Document Library.
This information you provided in the blog that is really unique I love it!! Thanks for sharing such a great blog. Keep posting..
ReplyDeleteSharepoint training in Noida
Sharepoint course in Noida
Sharepoint training institute in Noida
This information you provided in the blog that is really unique I love it!! Thanks for sharing such a great blog. Keep posting..
ReplyDeleteSharepoint training in Delhi
Sharepoint training institute in Delhi
Sharepoint course in Delhi
good information provided for more visit SharePoint Training in Texas
ReplyDeleteplz visit www.webdesignerhouston.com for SharePoint service at affordable price and quality service for your business
ReplyDelete
ReplyDeleteGood Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging
Sharepoint Admin Training in Electronic City
Nice post. By reading your blog, i get inspired and this provides some useful information. Thank you for posting this exclusive post for our vision.
ReplyDeleteArtificial Intelligence Online Training
Java Online Training
AWS Online Training
Machine Learning Online Training
Data Science Online Training
DevOps Online Training
Thanks For sharing
ReplyDeletefull stack training in delhi
AI training course in Delhi
Power BI Institute in Delhi
tableau training in delhi
SASVBA
GMB
For more information
this is really amazing, this article has a very good information which is very useful. thanks for it. Visit us for looking lands in Hyderabad Open Plots Near Sadasivpet Telangana
ReplyDelete