Server relative urls must start with SPWeb.ServerRelativeUrl – SharePoint Online Powershell error message?

Hello SharePointers,

When you user Server relative urls in sharepoint online powershell , please ensure that you provide only relative urls to the copyto function. For example

For instance, If you have following piece of code

     $file =$ctx.Web.GetFileByServerRelativeUrl($att.ServerRelativeUrl)

Write-Host $file.Name
$ctx.Load($file)
$ctx.ExecuteQuery()
Write-Output “Hello”
$NewName=$file.Name

if($DestinationLibrary.EndsWith(“/”)){}
else {$DestinationLibrary=$DestinationLibrary+”/”}
Write-Host “Processing ” $file.Name
$file.CopyTo($DestinationLibrary + $NewName, $Overwrite)

Please ensure that your destination library value should be relative url such as document name instead of site/document name.  Hope that helps!!

Happy sharepointing 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *