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.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.
I expect to see the file move from source location to the target location
This is the error returned:
Move-PnPFile : Server relative urls must start with SPWeb.ServerRelativeUrl
At line:1 char:1
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.
(you can retrieve this by executing Get-Module -Name *pnppowershell* -ListAvailable)
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Binary 2.19.1710.2 SharePointPnPPowerShellOnline {Add-PnPApp, Add-PnPClientSidePage, Add-PnPClientSidePageSection, Add-PnPClientSideText...}
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'm getting the same error. I'm using the latest version of SharePointPnPPowerShellOnline (2.21.1712.2)
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
+1 for me too even with latest SharePointPnPPowerShellOnline v3.0.1808.1
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.MoveFileI have the same problem!
@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).
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.
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.
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
I am trying to use Move-PnPFile to move files from Sharepoint Document library folder to Onedrive folder. Is this possible using powershell?
Any progress on this issue? Facing the same problem.
Same issue here. Is this expected behavior now?
Also, like @rgmatthes, Copy-PnPFile works for me but Move-PnPFile does not.
Facing the same issue. Receiving the message: Move-PnPFile : Server relative urls must start with SPWeb.ServerRelativeUrl
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...
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.
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
@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).
@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.
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.
@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?
Hi @HeKr09
I just downloaded the newest available version of the SharePointPnPPowershellOnline module, and I do see the parameter:
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'.
I thought I pasted your code... But I needed to put TargetServerRelativeLibrary as the first parameter :( It worked. Thank you!
Most helpful comment
I have exactly the same bug with exactly same version.
For example, my script in attachment. issue.txt
And the output :