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