SharePoint Document Issues

How to Copy SharePoint Files and Folders Using PnP PowerShell

Ayan MasoodAyan Masood Oct 28, 2026 868 views

Question details

The user needs to copy files and folders between SharePoint document libraries using PnP PowerShell, but the command executes silently without actually copying the data.

How to Copy SharePoint Files and Folders Using PnP PowerShell
Product
SharePoint Online
Device & OS
not provided
Scenario
Automating the migration or duplication of documents and directories across SharePoint sites or libraries using PowerShell scripting.
Observed behavior
The Copy-PnPFile command runs smoothly without throwing any errors, but no items are transferred to the destination library, typically due to improperly formatted URLs.
Before you start

Ensure you have the latest PnP.PowerShell module installed, verify that you have edit permissions on both the source and target SharePoint sites, and identify the exact library names.

Solution 1Recommended

Use Correct Library-Relative Paths in Copy-PnPFile

Fix silent script failures by replacing full browser URLs and encoded characters with clean, library-relative paths before executing the copy command.

The most common reason the Copy-PnPFile command fails silently is the use of browser-copied URLs. These often contain 'Forms/AllItems.aspx', encoded spaces (like '%20'), or specific view IDs. PnP PowerShell requires clean, server-relative or library-relative paths to locate your files accurately.

1
Format the Source URL

Define your source variable as a specific folder path relative to the library. Avoid using the root folder directly if it causes issues. Example: $SourceFolderURL = 'Shared Documents/Courses and Training'

2
Format the Target URL

Set your destination variable to the target library's server-relative path. Example: $TargetFolderURL = '/sites/TargetSiteName/Shared Documents'

3
Connect to SharePoint

Authenticate to your SharePoint environment by running: Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential) or use an interactive login.

4
Execute the Copy Command

Run the copy operation by executing: Copy-PnPFile -SourceUrl $SourceFolderURL -TargetUrl $TargetFolderURL -Force

Use Correct Library-Relative Paths in Copy-PnPFile
Path Formatting Success: Using exact string paths without encoded '%20' characters or query parameters ensures the module successfully identifies and copies your SharePoint files.
Free Microsoft Office alternative

Manage Your Migrated Documents Seamlessly with WPS Office

While managing complex SharePoint migrations via PowerShell, you need a reliable and fast office suite to open, review, and edit the documents you transfer. WPS Office is a fully compatible, lightweight, and free alternative to Microsoft Office that easily handles your Word, Excel, and PowerPoint files.

  1. 1. Download WPS Office: Visit the official WPS website and download the free installation package for your operating system.
  2. 2. Install the Suite: Run the installer and follow the on-screen prompts to set up WPS Office on your computer.
  3. 3. Open Your Documents: Launch WPS Office and open your synchronized or downloaded SharePoint files to start editing immediately.
Fully compatible with Microsoft Office formats (.docx, .xlsx, .pptx) stored in SharePoint.Extremely lightweight with a tabbed interface for managing multiple documents effortlessly.Free to download and use, providing familiar formatting and editing tools without the steep learning curve.Built-in PDF editor to view, annotate, and convert documents to streamline your workflow.
microsoft office alternative - wps office

Frequently Asked Questions

Why does Copy-PnPFile run without errors but do nothing?

This typically occurs when the Source URL or Target URL is formatted incorrectly. If you paste a browser URL containing 'Forms/AllItems.aspx' or encoded characters like '%20' for spaces, the module fails to locate the actual file path but often won't throw a terminating error.

Can I copy an entire root document library using a single Copy-PnPFile command?

Using just the root path (e.g., 'Shared Documents/') often fails in basic PnP PowerShell operations. To copy everything, you should write a script that iterates through the items within the root directory, or use Power Automate for bulk root-level migrations.

Do I need administrative permissions to run PnP PowerShell copy commands?

Yes, you must have adequate permissions on both the source and destination SharePoint sites. Typically, you need at least Site Member (Edit) or Site Owner (Full Control) rights to authenticate successfully and transfer files.