使用“4”个参数调用“CopyFolder”时发生异常:“‘destUrl’参数无效。”

使用“4”个参数调用“CopyFolder”时发生异常:“‘destUrl’参数无效。”

我正在尝试将本地驱动器文件夹复制到在线驱动器中的目标文件夹,但出现上述错误。

以下是尝试的代码:-

#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

答案1

我认为这需要一条道路

$TargetFolder="System_Data"

像这样

$TargetFolder="/personal/smith_office_com/System_Data"

相关内容