This blog will help you to upload a file into SharePoint Online, using PowerShell method.
Steps
  1. Open SharePoint Management Shell.
  2. Copy the code given below and paste it.
  3. Run the code.
  1. ##########################
  2. #Script : Below Script will upload file with metadata in Office 365 SharePoint Online
  3. #Author : Gowtham Rajamanickam
  4. #Date :16-03-2017
  5. #Version:1.0
  6. #########################
  7. #Before Run the Scritp you must load the Client Assembly files
  8. Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
  9. Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
  10. $UserName= "[email protected]"
  11. $Password = "Enter your Password here"
  12. $SiteUrl =https://gowthamr.sharepoint.com
  13. $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
  14. $Context = New-Object Microsoft.SharePoint.Client.ClientContext()
  15. $Context.credentials = $credentials
  16. $filePath = "C:\Documents\GowthamsTutorialGuide.docx"
  17. $listTitle = "MigratedDocuments"
  18. $targetList = $Context.Web.Lists.GetByTitle($listTitle) #target list
  19. $fci= New-Object Microsoft.SharePoint.Client.FileCreationInformation
  20. $fci.Overwrite = $true
  21. $fci.Content = [System.IO.File]::ReadAllBytes($filePath)
  22. $fci.URL = [System.IO.Path]::GetFileName($filePath)
  23. $uploadFile = $targetList.RootFolder.Files.Add($fci)
  24. #Set metadata properties
  25. $listItem = $uploadFile.ListItemAllFields
  26. $listItem["LastReviewed"] = [System.DateTime]::Now
  27. $listItem.Update()
  28. $Context.Load($uploadFile)
  29. $Context.ExecuteQuery()
Was my blog helpful? Was any relevant content missing? If so, please let us know what's confusing or missing at the bottom of this page.

Thanks for reading my blog.