First, you will have to connect to your SharePoint Online Site using the following command.
Connect-PnPOnline -Url https://<Your-tenant-name>.sharepoint.com/sites/<your-site-name>
Add-PnPFile
The Add-PnPFile command is used to upload the document file to the SharePoint library.
Example 1
This example uploads the local file specified in the Local FilePath to the Shared Documents folder.
Add-PnPFile -Path "D:\NewFiles\PnPPowershell.docx" -Folder "Shared Documents"

Output

Example 2
This example uploads the local file specified in the Local FilePath to the Shared Documents folder with a different name.
Add-PnPFile -Path "D:\NewFiles\PnPPowershell.docx" -Folder "Shared Documents" -NewFileName "NewPnPPowershell.docx"

Output

Example 3
This example uploads the file PnPPowershell.docx to the Shared Documents folder. After uploading, it will set the modified date to 1/5/2019.
Add-PnPFile -Path "D:\NewFiles\PnPPowershell.docx" -Folder "Shared Documents" -Values @{Modified="1/5/2019"}

Copy-PnPFile
The Copy-PnPFile command is used to copy a file or folder to a different location.
Example 1
This example copies a file named PnPPowershell.docx located in a document library called NewDoc to a new document named NewPnPPowershell.docx in the same library.
Copy-PnPFile -SourceUrl NewDoc/PnPPowershell.docx -TargetUrl NewDoc/NewPnPPowershell.docx

Output

Example 2
This example copies a file named PnPPowershell.docx located in a document library called NewDoc in the current site to another site collection ModernSite.
Copy-PnPFile -SourceUrl NewDoc/PnPPowershell.docx -TargetUrl /sites/ModernSite/Doc/PnPPowershell.docx

Note
If a file named PnPPowershell.docx already exists, it won't perform the copy operation.
If a file named PnPPowershell.docx already exists, it won't perform the copy operation.
Output

Find-PnPFile
The Find-PnPFile command is used to find a file in the file system of the web.
Example 1
Find-PnPFile -List "Documents" -Match *.docx
This example returns all the .docx files located in a given library.

Example 2
Find-PnPFile -Folder "Shared Documents/SubFolder" -Match *.pdf
This example returns all the .docx files located in the given folder.















Lakshman ThilakaratnePosted Nov 18, 2020, 12:22 PM
How can we download files from SharePoint using C# or PowerShell when MFA is enabled?