0

I'm trying to copy local drive folder to targeted folder in online one drive but getting above error.

Below is the code tried: -

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

function SerialNumber{
$serial= Get-WmiObject win32_bios | Select Serialnumberreturn $serial.Serialnumber
}
$Path = "C:\$(SerialNumber)"
  
#Function to Copy a Folder
Function Copy-SPOFolder([String]$SiteURL, [String]$SourceFolder, [String]$TargetFolder)
{
    Try{
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
      
        #Copy the Folder
        $MoveCopyOpt = New-Object Microsoft.SharePoint.Client.MoveCopyOptions
        [Microsoft.SharePoint.Client.MoveCopyUtil]::CopyFolder($Ctx, $SourceFolder, $TargetFolder, $MoveCopyOpt)
        $Ctx.ExecuteQuery()
  
        Write-host -f Green "Folder Copied Successfully!"
    }
    Catch {
    write-host -f Red "Error Copying the Folder!" $_.Exception.Message
    }
}
  
#Set Config Parameters
$SiteURL="https://myoffice.com/personal/smith_office_com"
$SourceFolder= $Path
$TargetFolder="System_Data"
  
#Get Credentials to connect
$Cred= Get-Credential
  
#Call the function to Copy the Folder
Copy-SPOFolder $SiteURL $SourceFolder $TargetFolder
2
  • As message said: “destUrl” is invalid, review it.
    – Toto
    Commented Nov 22, 2022 at 11:24
  • Furthermore and more specifically, the function has 3 arguments defined yet the error message from the title of your post indicates an issue with the 4th argument. I would suggest ensuring your arguments are enclosed with double quotes (e.g. "C:\Path\Folder 123") to ensure the 3rd argument if it contains spaces is not interpreted by the function as 2 separate arguments thus the error regarding the 4th argument which the title of your post indicates. Commented Nov 23, 2022 at 14:31

1 Answer 1

0

I think that this needs to be a path

$TargetFolder="System_Data"

like this

$TargetFolder="/personal/smith_office_com/System_Data"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .