2016-07-05 5 views
1

を使用して他のために、SharePointから多くのファイルをコピー:私は別の1つのSharePointのリストから文書をコピーしようとしているメートルのPowerShell

これは私のコードです:

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

foreach ($result in $result) 

{ copy-item -path $source -dest $destination} 
************************************************* 

-$resultは、すべての文書の一覧です私は、Webサービスを使用して得た、それがタイプだ

-$source$destinationがUNCのSystem.Arrayある2つのSharePoint

のURLを参照します

エラーが

"パスが見つかりません\ ... \ s1system.xml.Xml.XmlElement"

PSされています。私は、サーバー・マシンを使用していないM、それだけで、クライアントよここで

は私のコードはおそらく、あなたが持っている問題は、変換の問題の結果である

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




{ 

    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 } 

} 
+0

'foreachの($ $結果につながります)'私には疑わしい。私は 'foreach($ doc in $ result)'を試してみたいと思います。また、この配列の内容を調べる必要があります。完全なオブジェクトの代わりに 'copy-item'に渡すためにプロパティにアクセスする必要があるかもしれません。 – Filburt

+0

これはlisteNameですが、new-webserviceproxyというコマンドを使用しています。ows_linkFileName、ows_modified ..... – ajar

答えて

1

です。あるSPから別のSPへのコンテンツをドキュメントとして書き込もうとしていますが、XmlElementを使用することはできません。 $結果は、私がウェブサービスを使用してしまったすべての文書のリストである、それはSタイプのSystem.Arrayある - Converting system.xml.xmlelement to system.xml.xmldocument with PowerShell

」の内容を見て参考になる:

は、この記事をチェックアウトすると提案します"

また、読みやすくするために、私は次のように$result$result区別することをお勧め:

foreach($document in $documentList){} 

- または - (最低でも)

foreach($result in $results){} 
+0

コードが表示されますか? – ajar

関連する問題