Forum Discussion
Copy-PnPFile Not Working Value cannot be null.\r\nParameter name: Null value for source item at
I'm tying to use Copy-PnPFile command to copy all files and folders from site collection A document library to another site collection B/folder but it's not working. Following is the command I'm using:
Copy-PnPFile -SourceUrl "/sites/AshTest/Docs" -TargetUrl "/sites/ADM-AshTest/TestDocs/Docs" -Force
Error, please let me know what can be done to make it work.
Copy-PnPFile : {"odata.error":{"code":"-2147467261, System.ArgumentNullException","message":{"lang":"en-US","value":"Value cannot be null.\r\nParameter name: Null value for source item at
https://tenant.sharepoint.com/sites/AshTest/Docs"}}}
At line:1 char:1
+ Copy-PnPFile -SourceUrl "/sites/AshTest/Docs" -TargetUrl "/sites/ADM- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Copy-PnPFile], HttpRequestException
+ FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Files.CopyFile
4 Replies
- MarceloMendesCopper Contributor
I've had the same issue and it turns out that you can use it for the root folder, but it contains a hidden forms folder that is the default folder MS uses for Microsoft Forms for that Sharepoint site. When copying at root folder level, you have to make sure you're excluding the forms folder like
$folder.name -ne "Forms"
- AmityTechAusOccasional Reader
I like the sound of this, but I can't figure out how to use your exclusion in the syntax for this command.
(Sorry, I'm brand new to Powershell, and just trying to use it for the first time to migrate some Sharepoint sites.)
For example, how would I incorporate $folder.name -ne "Forms" into the following example?
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Marketing"
$SourceFolderURL = "/sites/Marketing/Shared Documents"
$TargetFolderURL = "/sites/Purchase/Shared Documents"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Copy All Files and Folders between source and target folders
Copy-PnPFile -SourceUrl $SourceFolderURL -TargetUrl $TargetFolderURL -Force -OverwriteIfAlreadyExists
AshMSport Is there any required column in destination site library for which you are passing null values from source site library?
If yes, try removing required settings from column for time being while copying files using PowerShell.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
- AshMSportCopper ContributorThere are no required fields.