Version History Issues

How to Copy a Specific SharePoint File Version with PnP PowerShell

John WilsonJohn Wilson Nov 3, 2026 869 views

Question details

The user needs to copy the published version of a SharePoint file, regardless of its current draft or pending status, using PnP PowerShell.

How to Copy a Specific SharePoint File Version with PnP PowerShell
Product
SharePoint / PnP PowerShell
Device & OS
not provided
Scenario
Attempting to copy specific file versions across SharePoint document libraries where strict content approval and versioning are enabled.
Observed behavior
The standard Copy-PnPFile command skips files that are currently in a draft state, even when the user has access, preventing the successful duplication of the desired published version.
Before you start

Ensure you have the latest PnP PowerShell module installed and that your account possesses sufficient SharePoint site permissions to read all document versions and draft items.

Solution 1Recommended

Use a Custom PnP PowerShell Script to Fetch the Specific Version

Because standard copy commands often skip draft files, utilizing a custom script allows you to explicitly retrieve and download the required published version from the file's history.

When SharePoint content approval is active, the Copy-PnPFile cmdlet may behave unpredictably with files in draft or pending states. To bypass this limitation, you can interact directly with the file's version collection to extract the exact data stream you need.

1
Connect to the SharePoint Environment

Open your PowerShell console and execute 'Connect-PnPOnline -Url <YourSiteUrl> -Interactive' to securely authenticate with your SharePoint site.

2
Retrieve the Target File and Version History

Use the 'Get-PnPFile -Url <YourFileUrl> -Includes Versions' command to fetch the file object along with its complete version history.

3
Iterate Through File Versions

Access the '.Versions' property on the retrieved file object to loop through the historical records and identify the exact published version you need based on its version label.

4
Download or Copy the Content

Once the target version is identified, use the specific PnP download commands or the file stream properties to save the version's contents locally before uploading it to the new destination.

Use a Custom PnP PowerShell Script to Fetch the Specific Version
Seek Scripting Assistance: For detailed examples on retrieving file streams or writing complex PowerShell logic, consider posting your specific requirements in the Microsoft Q&A forums.
Free Microsoft Office alternative

Seamlessly Edit Your Downloaded SharePoint Documents with WPS Office

After retrieving your specific SharePoint document versions via PowerShell, you need a reliable suite to open, view, and edit them. WPS Office provides a lightweight, highly compatible, and free alternative to Microsoft Office.

  1. 1. Download WPS Office: Visit the official WPS website to download the free installation package tailored for your operating system.
  2. 2. Install the Suite: Run the downloaded installer file and follow the simple on-screen instructions to complete the setup.
  3. 3. Open Your Documents: Launch WPS Office and instantly open your downloaded SharePoint file versions for seamless editing and review.
Fully compatible with Microsoft Office file formats (.docx, .xlsx, .pptx).Lightweight application that runs smoothly and opens large documents quickly.Familiar user interface ensuring a seamless migration from Microsoft Office.Built-in PDF editing tools alongside advanced Word, Excel, and Presentation functions.
microsoft office alternative - wps office

Frequently Asked Questions

Why does Copy-PnPFile skip certain documents during the copy process?

When SharePoint content approval and versioning are strictly enabled, the Copy-PnPFile command may skip files that are currently in draft or pending status, as it primarily targets default published versions.

How can I find the exact version number of a SharePoint file using PowerShell?

You can use the Get-PnPFile command along with the -Includes Versions parameter to retrieve the file object, and then iterate through its .Versions property to view the specific version labels and IDs.

Where can I get help writing custom PnP PowerShell scripts?

For detailed scripting assistance and complex version retrieval logic, you can post your specific scenario and script attempts in the Microsoft Q&A forums for expert community support.