![](/img/trans.png)
[英]Getting Exception calling “Execute” with “1” argument(s): “The remote server returned an error: (400) Bad Request.” error
[英]Error Copying the Folder! Exception calling "ExecuteQuery" with "0" argument(s): "The remote server returned an error: (400) Bad Request."
对于背景,我试图将每天更新文件的目录的内容复制到 SharePoint Online,组织中各部门的许多用户都可以访问该目录。 任何指导将不胜感激!
错误信息
'复制文件夹时出错! 使用“0”参数调用“ExecuteQuery”的异常:“远程服务器返回错误:(400) 错误请求。”'
#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 Extension\16\ISAP\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extension\16\ISAP\Microsoft.SharePoint.Client.WorkflowServices.dll"
#Function to Copy a Folder
Function Copy-SPOFolder([String]$SiteURL, [String]$SourceFolderURL, [String]$TargetFolderURL)
{
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, $SourceFolderURL, $TargetFolderURL, $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://domain.sharepoint.com/sites/US-LocationMaster/"
$SourceFolderURL="C:\US-Location Files\"
$TargetFolderURL="https://domain.sharepoint.com/sites/US-LocationMaster/Documents/"
#Get Credentials to connect
$Cred= Get-Credential
#Call the function to Copy the Folder
Copy-SPOFolder $SiteURL $SourceFolderURL $TargetFolderURL
免责声明:我无法测试这个,因为我没有程序集,我只是通过眼睛来做这个。
从我几分钟的研究来看,我认为在这种情况下不需要调用ExecuteQuery()
方法。
就目前而言,我没有看到$Ctx
加载了任何查询,所以我没有看到ExecuteQuery()
方法做太多事情。
当谈到这一点时
[Microsoft.SharePoint.Client.MoveCopyUtil]::CopyFolder($Ctx, $SourceFolderURL, $TargetFolderURL, $MoveCopyOpt)
从文档来看,它似乎执行了我们需要的操作,因此我将删除$Ctx.ExecuteQuery()
并查看代码是否正确执行其操作。
如果该行创建了一个对象,请尝试在$Ctx
上使用Load()
方法,然后使用ExecuteQuery()
方法。
它看起来有点像这样
Function Copy-SPOFolder([String]$SiteURL, [String]$SourceFolderURL, [String]$TargetFolderURL)
{
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
$Ctx.Load([Microsoft.SharePoint.Client.MoveCopyUtil]::CopyFolder($Ctx, $SourceFolderURL, $TargetFolderURL, $MoveCopyOpt))
$Ctx.ExecuteQuery()
Write-host -f Green "Folder Copied Successfully!"
}
Catch {
write-host -f Red "Error Copying the Folder!" $_.Exception.Message
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.