Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用powershell将许多文件从sharepoint复制到其他站点_Powershell_Sharepoint - Fatal编程技术网

使用powershell将许多文件从sharepoint复制到其他站点

使用powershell将许多文件从sharepoint复制到其他站点,powershell,sharepoint,Powershell,Sharepoint,我正在尝试将文档从一个sharepoint中的列表复制到另一个sharepoint中: 这是我的代码: ************************************************* $source= "\\...\s1" $destination = "\\..\s2" foreach ($result in $result ) { copy-item -path $source -dest $destination} *************************

我正在尝试将文档从一个sharepoint中的列表复制到另一个sharepoint中:

这是我的代码:

*************************************************
$source= "\\...\s1"
$destination = "\\..\s2"

foreach ($result in $result )

{ copy-item -path $source -dest $destination}
*************************************************
-$result
是我使用web服务获得的所有文档的列表,其类型为system.array

-$source
$destination
是引用两个sharepoint的URL的UNC

错误是

“找不到路径\…\s1system.xml.xml.XmlElement”

PS:我没有使用服务器,它只是一个客户端

这是我的密码

*****************************************************




{

  param (

    [String]$Value,
    [String]$Field,
    [String]$RowLimit = "0",
    [String]$Operator = "Contains",
    [String]$WebURL = "https://.................../wer",
    [String]$ListName = "Main documents",
    [String]$ViewName,
    [Switch]$Recurse
)
$ScriptDirectory = split-path $MyInvocation.MyCommand.Definition
$dllPath = "P:\SamlCookieAuth.dll" -f $ScriptDirectory
[void][System.Reflection.Assembly]::LoadFrom($dllPath)

$queryOptionsValue = ''
if ($Recurse)
{
    $queryOptionsValue = '<ViewAttributes Scope="RecursiveAll"/>'
}

$WSUri = $WebURL + "/_vti_bin/Lists.asmx?wsdl"
$listsWebServiceReference = New-WebServiceProxy -Uri $WSUri -UseDefaultCredential
$listsWebServiceReference.Url = $webURL + "/_vti_bin/lists.asmx"

[System.Uri]$CookieUri = $WebURL
$listsWebServiceReference.CookieContainer = [ST.SamlCookieAuth.SamlCookieManager]::GetAuthenticatedCookiesContainer($CookieUri.AbsoluteUri, 0, 0)

[System.Xml.XmlDocument]$xmlDoc = New-Object -TypeName System.Xml.XmlDocument
[System.Xml.XmlElement]$queryOptions =$xmlDoc.CreateElement("QueryOptions")
$queryOptions.InnerXml = $queryOptionsValue

if ($PSBoundParameters.Keys.Contains("Value"))
{
    [System.Xml.XmlElement]$query = $xmlDoc.CreateElement("Query")
    $queryValue = "<Where><$Operator><FieldRef Name='$Field'/><Value Type='Text'>$Value</Value></$Operator></Where>"
    $query.InnerXml = $queryValue
    $result=$listsWebServiceReference.GetListItems($listName, $viewName, $query, $null, $rowLimit, $queryOptions, $null).data.row
}
else
{
    $result=$listsWebServiceReference.GetListItems($listName, $viewName, $null, $null, $rowLimit, $queryOptions, $null).data.row
}




 $destDirectory = "\\.............\TER\Main Documents"

foreach ($resul in $result)

 {Copy-Item -path $resul -destination $destDirectory } 

}
*****************************************************
{
param(
[字符串]$Value,
[字符串]$Field,
[String]$RowLimit=“0”,
[String]$Operator=“Contains”,
[字符串]$WebURL=”https://.................../wer",
[String]$ListName=“主文档”,
[字符串]$ViewName,
[开关]$Recurse
)
$ScriptDirectory=拆分路径$MyInvocation.MyCommand.Definition
$dllPath=“P:\SamlCookieAuth.dll”-f$ScriptDirectory
[void][System.Reflection.Assembly]::LoadFrom($dllPath)
$QueryOptions值=“”
如果($Recurse)
{
$QueryOptions值=“”
}
$WSUri=$WebURL+“/\u vti\u bin/Lists.asmx?wsdl”
$listsWebServiceReference=新的WebServiceProxy-Uri$WSUri-UseDefaultCredential
$listsWebServiceReference.Url=$webURL+“/\u vti\u bin/lists.asmx”
[System.Uri]$CookieUri=$WebURL
$listsWebServiceReference.CookieContainer=[ST.SamlCookieAuth.SamlCookieManager]:GetAuthenticatedCookiesContainer($CookieUri.AbsoluteUri,0,0)
[System.Xml.XmlDocument]$xmlDoc=新对象-TypeName System.Xml.XmlDocument
[System.Xml.xmlement]$queryOptions=$xmlDoc.CreateElement(“queryOptions”)
$queryOptions.InnerXml=$queryOptions值
if($PSBoundParameters.Keys.Contains(“Value”))
{
[System.Xml.xmlement]$query=$xmlDoc.CreateElement(“查询”)
$queryValue=“$Value”
$query.InnerXml=$queryValue
$result=$listsWebServiceReference.GetListItems($listName、$viewName、$query、$null、$rowLimit、$queryOptions、$null)。data.row
}
其他的
{
$result=$listsWebServiceReference.GetListItems($listName,$viewName,$null,$null,$rowLimit,$queryOptions,$null)。data.row
}
$destDirectory=“\\....\TER\Main Documents”
foreach($result in$result)
{复制项-路径$resl-目标$destDirectory}
}

您遇到的问题可能是转换问题的结果。您试图将内容作为文档从一个SP写入另一个SP,但是,不能使用XmlElement

建议查看此帖子:

查看“-$result是我使用web服务获得的所有文档的列表,它的类型是system.array”,这会很有帮助

此外,为了可读性,我建议将
$result
$result
区分如下:

foreach($document in $documentList){}
-或—(至少)


foreach($result in$result)
在我看来很可疑。我会尝试
foreach($result中的doc)
。您还应该检查此数组中的内容-可能是您必须访问一个属性才能传递到
复制项
,而不是完整的对象。这是一个ListName,我使用命令new-webserviceproxy获得。它包含如下属性:ows_linkFileName,ows_modified…..您能看到may code吗?
foreach($result in $results){}