pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
987 stars 665 forks source link

Move-PnPFile returning error when moving between Site Collections #1198

Open NicholasMiller3 opened 6 years ago

NicholasMiller3 commented 6 years ago

Notice: many issues / bugs reported are actually related to the PnP Core Library which is used behind the scenes. Consider carefully where to report an issue:

  1. Are you using Apply-SPOProvisioningTemplate or Get-SPOProvisioningTemplate? The issue is most likely related to the Provisioning Engine. The Provisioning engine is not located in the PowerShell repo. Please report the issue here: https://github.com/officedev/PnP-Sites-Core/issues.
  2. Is the issue related to the cmdlet itself, its parameters, the syntax, or do you suspect it is the code of the cmdlet that is causing the issue? Then please continue reporting the issue in this repo.
  3. If you think that the functionality might be related to the underlying libraries that the cmdlet is calling (We realize that that might be difficult to determine), please first double check the code of the cmdlet, which can be found here: https://github.com/OfficeDev/PnP-PowerShell/tree/master/Commands. If related to the cmdlet, continue reporting the issue here, otherwise report the issue at https://github.com/officedev/PnP-Sites-Core/issues

Reporting an Issue or Missing Feature

When I use the Move-PnPFile cmdlet I enter it just as the example shows:

Move-PnPFile -ServerRelativeUrl "/sites/Ops/west/r01/5022/Community Reports/Heath fair vendor list.xlsx" -TargetUrl "/sites/opsarc/opspurgedl/Heath fair vendor list.xlsx"

However, an error is returned and the file is not moved.

Expected behavior

I expect to see the file move from source location to the target location

Actual behavior

This is the error returned:

Move-PnPFile : Server relative urls must start with SPWeb.ServerRelativeUrl At line:1 char:1

Steps to reproduce behavior

I've tried removing the first "/" without success, but I didn't think that would work anyway. I've created variables for the ServerRelativeURL and TargetURL and got the same result. I'm attempting to archive approx. 5,000 documents throughout 639 sites to purge old documents, but have a backup if needed.

Which version of the PnP-PowerShell Cmdlets are you using?

What is the version of the Cmdlet module you are running?

(you can retrieve this by executing Get-Module -Name *pnppowershell* -ListAvailable)

[DBG]: PS C:\Users\nicholas.miller>> Get-Module -Name pnppowershell -ListAvailable | Format-Table -AutoSize

Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version Name ExportedCommands


Binary 2.19.1710.2 SharePointPnPPowerShellOnline {Add-PnPApp, Add-PnPClientSidePage, Add-PnPClientSidePageSection, Add-PnPClientSideText...}

How did you install the PnP-PowerShell Cmdlets?

Reclad commented 6 years ago

I have exactly the same bug with exactly same version.

For example, my script in attachment. issue.txt

And the output :

Move-PnpFile : Server relative urls must start with SPWeb.ServerRelativeUrl
Au caractère ***\Delete-DuplicateFilesSP - Copie.ps1:22 : 9
+         Move-PnpFile -ServerRelativeUrl $file.ServerRelativeUrl -Targ ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : WriteError: (:) [Move-PnPFile], ServerException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Files.MoveFile
robbert-vanandel commented 6 years ago

I'm getting the same error. I'm using the latest version of SharePointPnPPowerShellOnline (2.21.1712.2)

kallejar commented 6 years ago

I have following problem when moving document between two sites (communication site template): Move-PnPFile : Access denied. You do not have permission to perform this action or access this resource.

Move-PnPFile -ServerRelativeUrl "/sites/site1/library/TestMove.docx" -TargetUrl "/sites/site2/library/TestMove.docx"

PnP Online version is 2.22.1801.0

The account that I have been using has SharePoint Admin role and I added it also in the site collection administrators group to test. Via GUI I can access sites correctly.

I can move the document just fine within the same site collection.


I also tried between two traditional sites and there I get the same as in the origal post: Move-PnPFile : Server relative urls must start with SPWeb.ServerRelativeUrl


Update 28.2.2018. I noticed that when I enable the customization vie SPO mgmt shell the access denied message goes away, but I get another.

So what I did: Connect-SPOService https://<tenant>-admin.sharepoint.com Set-SPOsite https://<tenant>.sharepoint.com/sites/<site> -DenyAddAndCustomizePages 0

And then when I try to move the page/document it says that it can't find the folder. Not even when you have file in the root of the document library. `Move-PnPFile : Folder "content" does not exist. At line:1 char:1

CReamflourish commented 6 years ago

+1 for me too even with latest SharePointPnPPowerShellOnline v3.0.1808.1

RedhwanGhailan commented 5 years ago

I have exactly the same bug with exactly same version.

For example, my script in attachment. issue.txt

And the output :

Move-PnpFile : Server relative urls must start with SPWeb.ServerRelativeUrl
Au caractère ***\Delete-DuplicateFilesSP - Copie.ps1:22 : 9
+         Move-PnpFile -ServerRelativeUrl $file.ServerRelativeUrl -Targ ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : WriteError: (:) [Move-PnPFile], ServerException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Files.MoveFile

I have the same problem!

bkadhim commented 5 years ago

@RedhwanGhailan I notice that in your script you are connecting to the original site rather than the root, i.e., you use

Connect-PnpOnline -Url "https://$orgName.sharepoint.com/sites/$site" -Credentials $userCredential

rather than:

Connect-PnpOnline -Url "https://$orgName.sharepoint.com/" -Credentials $userCredential

I don't know that this is correct, however, because now it complains that it cannot open the file ("no such file or folder"), though I don't know if this is because it is a private site (that I should have access to).

rgmatthes commented 5 years ago

Confirming this bug on v3.9.1905.1. I'm trying to move files across site collections, something akin to:

Source: https://domain.sharepoint.com/project1/shared documents (a library) Destination: https://domain.sharepoint.com/archives/shared documents/project1 (a folder)

I'm getting either:

"Specified value is not supported for the serverRelativePath parameter." (if I include a forward slash in the ServerRelativeUrl) "Server relative urls must start with SPWeb.ServerRelativeUrl" (if I don't)

Copy-PnPFile seems to work just fine, so it was surprising that the Move equivalent doesn't work.

RamaKaryam commented 4 years ago

Source url starts with '/' & Target url starts with '/' Move-PnPFile : Server relative urls must start with SPWeb.ServerRelativeUrl At line:1 char:1

Source url has no starting '/' & Target url has no starting '/' Move-PnPFile : serverRelativePath Parameter name: Specified value is not supported for the serverRelativePath parameter. At line:1 char:1

Source url doesn't start with '/' and Target url starts with '/' Move-PnPFile : serverRelativePath Parameter name: Specified value is not supported for the serverRelativePath parameter. At line:1 char:1

Source url starts with '/' and Target url doesn't start with '/' Move-PnPFile : Access denied. You do not have permission to perform this action or access this resource. At line:1 char:1

When DenyAddAndCustomizePages is disabled on BOTH source and target (otherwise behavior is same as above) AND Source url starts with '/' and target url doesn't start with '/' (otherwise same as corresponding case above) (@kallejar) Move-PnPFile : Folder "The folder before file name" does not exist. At line:1 char:1

Connecting to root instead of the actual source site (@bkadhim) It just says no such file or folder.

@VesaJuvonen @erwinvanhunen may be this helps.

RamaKaryam commented 4 years ago

File.MoveTo in CSOM is giving similar errors. However, the MicroSoft Flow's Move File action is doing it right. Versions and metadata are coming through as well. Didn't check with various permissions in Flow but I have full control on source and destination sites. @chakkaradeep

innoventix-solutions commented 4 years ago

I am trying to use Move-PnPFile to move files from Sharepoint Document library folder to Onedrive folder. Is this possible using powershell?

mmartain commented 4 years ago

Any progress on this issue? Facing the same problem.

bsmetzer commented 4 years ago

Same issue here. Is this expected behavior now?

Also, like @rgmatthes, Copy-PnPFile works for me but Move-PnPFile does not.

Pofile commented 4 years ago

Facing the same issue. Receiving the message: Move-PnPFile : Server relative urls must start with SPWeb.ServerRelativeUrl

ysguy commented 4 years ago

Same issue as others reported & I need this to work. Mover.io doesn't support sharepoint->sharepoint moves, neither does the sharepoint web browser move functions. Other than saving the library as a template and restoring, i dont know what else is even possible to consolidate sites.

I tried many many combinations of relative and direct URL's with the powershell commands, but nothing yields any useful results.

Move-PnPFile and Move-PnPFolder both affected. Will try Copy but don't want to leave the old library data active...

freddie0216 commented 4 years ago

facing same issue, and Microsoft support said they are not responsible for this one, while it is obviously showing on the TechNet that Move-PnPFile is technically available for users to use. I cannot believe Microsoft can ignore the absolute bugs for years but still declare it is working.

PowershellNinja commented 4 years ago

For all those experiencing this issue when trying to run:

Move-PnPFile -ServerRelativeUrl "sites/SourceSite/DocumentLibrary/file.ending" -TargetUrl "sites/DestinationSite/DocumentLibrary/file.ending" -Force

I have to say: the documentation is wrong regarding moving files to another sitecollection.

After checking the current master branch code I found you have to call the cmdlet like this to make it work:

Import-Module SharePointPnPPowerShellOnline

Connect-PnPOnline -Url "https://mytenant.sharepoint.com/sites/SourceSite" -UseWebLogin

$file = Get-PnPFile -Url "Freigegebene Dokumente/mysourcefile.ending"
$fileServerRelativeUrl = Get-PnPProperty -ClientObject $file -Property "ServerRelativeUrl"

$targetServerRelativeLibraryUrl = "/sites/DestinationSite/Shared Documents"

Move-PnPFile -ServerRelativeUrl $fileServerRelativeUrl -TargetServerRelativeLibrary $targetServerRelativeLibraryUrl -Force

The Microsoft documentation (https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/move-pnpfile?view=sharepoint-ps) nowhere mentions this parameter called "TargetServerRelativeLibrary ", but I just verified myself that it perfectly works like this.

Edit: Seems this change was only introduced a short time ago, no wonder the documentation is not up to date. You can get the current help info by updating to the newst module version and running:

Get-Help Move-PnPFile -Full

or directly the examples by running:

Get-Help Move-PnPFile -Examples
wilecoyotegenius commented 4 years ago

@PowershellNinja Thank you for this info. However, it does not change the fact that TargetUrl should work as well, since it allows you to rename the file during move (with TargetServerRelativeLibrary you just point a destination folder, so filename stays the same).

PowershellNinja commented 4 years ago

@wilecoyotegenius Thats true, but not possible the way it is implemented currently. For now, you would have to work around this by renaming the file before or after the move using Rename-PnPFile.

wilecoyotegenius commented 4 years ago

In that case, maybe changing of the implementation of Rename-PnPFile should be considered, as it currently changes ModifiedDate and Editor values (Move-PnPFile leaves those pieces of information intact). I know that we can set those fields to original values again in Set-PnPListItem, but this would be yet another (unnecessary in my opinion) roundtrip to SharePoint.

HeKr09 commented 4 years ago

@PowershellNinja How did you get the parameter TargetServerRelativeLibrary? It is only available in the online version and I installed the online version but I do not see any parameter like this. Can you help me?

PowershellNinja commented 4 years ago

Hi @HeKr09

I just downloaded the newest available version of the SharePointPnPPowershellOnline module, and I do see the parameter: pnp

Can you please doublecheck you loaded the newest version using

Import-Module SharePointPnPPowershellOnline
Get-Module -Name SharePointPnPPowershellOnline | Select-Object -Property Name,Version

and make sure it is version 3.24.2008.1 or above?

Also, please note that the 'TargetServerRelativeLibrary' parameter is only available in one parameter set out of the three you can see on my screenshot. This means you would have to call the cmdlet like this I mentioned in my post above. Did you try that? For example, you cannot use the 'SiteRelativeUrl' or 'TargetUrl' parameters when using 'TargetServerRelativeLibrary'.

HeKr09 commented 4 years ago

I thought I pasted your code... But I needed to put TargetServerRelativeLibrary as the first parameter :( It worked. Thank you!