Upload a File in Microsoft SharePoint using PowerShell Script


PowerShell Script to upload file to SharePoint


$localFilePath = "D:\Annual Report\report-2023.xlsx"

if (-not (Get-Module -Name SharePointPnPPowerShellOnline -ListAvailable)) {
    Install-Module SharePointPnPPowerShellOnline -Force
}

$siteUrl = "https://your-tenant-name.sharepoint.com/sites/your-site-name"
Connect-PnPOnline -Url $siteUrl

$destinationLibrary = "Shared Documents"

Add-PnPFile -Path $localFilePath -Folder $destinationLibrary -NewFileName "report-2023.xlsx"

Disconnect-PnPOnline

Note that we are installing SharePoint PnP PowerShell module if not already installed using the script and uploading report-2023.xlsx from local D: drive to the SharePoint Shared Documents folder.


Do replace you tenent information in the siteURL.

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap