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
"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.