This blog will help you to upload a file into SharePoint Online, using PowerShell method.
Steps
- Open SharePoint Management Shell.
- Copy the code given below and paste it.
- Run the code.
- ##########################
-
- #Script : Below Script will upload file with metadata in Office 365 SharePoint Online
- #Author : Gowtham Rajamanickam
- #Date :16-03-2017
- #Version:1.0
-
- #########################
-
- #Before Run the Scritp you must load the Client Assembly files
-
- 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"
-
- $UserName= "[email protected]"
- $Password = "Enter your Password here"
- $SiteUrl =https:
-
- $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
- $Context = New-Object Microsoft.SharePoint.Client.ClientContext()
- $Context.credentials = $credentials
- $filePath = "C:\Documents\GowthamsTutorialGuide.docx"
- $listTitle = "MigratedDocuments"
- $targetList = $Context.Web.Lists.GetByTitle($listTitle) #target list
-
- $fci= New-Object Microsoft.SharePoint.Client.FileCreationInformation
- $fci.Overwrite = $true
- $fci.Content = [System.IO.File]::ReadAllBytes($filePath)
- $fci.URL = [System.IO.Path]::GetFileName($filePath)
- $uploadFile = $targetList.RootFolder.Files.Add($fci)
-
- #Set metadata properties
- $listItem = $uploadFile.ListItemAllFields
- $listItem["LastReviewed"] = [System.DateTime]::Now
- $listItem.Update()
-
- $Context.Load($uploadFile)
- $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.