2013 – Add-PnpFile fails when Approve parameter is added

Just as it says in the title. But its giving me an error that I believe is misleading.

When I run:

Add-PnpFile -Path ".ModernWebPartPage.aspx" -Checkout -Folder "/_catalogs/masterpage" it works out fine, and the file is registered as pending.

However when I run Add-PnpFile -Path ".ModernWebPartPage.aspx" -Checkout -Folder "/_catalogs/masterpage" -Approve I get the following error:

Add-PnpFile : The URL '_catalogs/masterpage/ModernWebPartPage.aspx' is invalid. It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current Web.

A couple of things about this. Notice that the url in the error message no longer has a leading slash. It appears to make it relative ignoring what I put as a parameter. And – the file is definitely there, but even if it wasn’t, I’m adding a file – it doesn’t need to be there.

I’m sure this is related to the Approve parameter, as I’m able to replicate this by running a similar command using Set-PnPFileCheckedOut and then Set-PnPFileCheckedIn. Works fine without the approve parameter.

This result holds true when I run it as the user from the command line and when I run it using a task runner that calls the command from a script.

Any tips on how to debug this?

Note: I’ve looked at this question and this question and neither seems to apply – and I wasn’t able to find anything to resolve my issue.