SharePoint オンライン サーバー上のあるリストから別のリストに項目をコピーするスクリプトを作成しています。私は 2013 年の sharepoint Client Side Object Model (CSOM) を使用して、powershell ISE でこれをスクリプト化しています。これは簡単な作業のはずですが、逆のことが証明されています。これまでのところ、camlquery を使用してすべてのアイテムを取得できます。これらのアイテムとその添付ファイルを別のリストに複製しようとしています。私が受け取ったエラーは、任意のアイテムからすべての添付ファイルを取得するために attachmentCollection を確立しようとしたことによるものです。問題を表すスクリプトの一部を次に示します。
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
$siteURL = "https://mysite.sharepoint.com"
$password = Read-Host -Prompt "Enter Password" -AsSecureString
$ctx = New-Object Microsoft.Sharepoint.Client.ClientContext($siteURL)
$credentials = New-Object Microsoft.Sharepoint.Client.SharepointOnlineCredentials("admin@mysite.sharepoint.com", $password)
$ctx.Credentials = $credentials
#...Bunch of code that establishes/loads web/lists/items, all works fine
function CopyItem $itemToCopy
function CopyItem ($oldItem)
{
Write-Host "Copying item" $oldItem.ID
$newItemCI = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$newItem = $archList.AddItem($newItemCI)
$ctx.load($newItem)
#Update fields
$ctx.load($sourceList.Fields)
$ctx.ExecuteQuery()
foreach($field in $sourceList.Fields)
{
$newItem[$field.InternalName] = $oldItem[$field.InternalName]
}
$attachments = New-Object Microsoft.SharePoint.Client.AttachmentCollection #ERROR HERE
$attachments = $oldItem.AttachmentFiles
$ctx.load($attachments)
$newItem.AttachmentFiles.Add($attachments)
$newItem.Update()
$ctx.load($newItem)
$ctx.ExecuteQuery()
}
エラー メッセージは次のとおりです。
新しいオブジェクトを添付ファイルとして作成しようとすると、同じエラーが発生し、コンストラクターが見つかりません。コンストラクターは client.dll にあるはずなので、これは奇妙ですが、うまくいきません。2013 CSOM ファイルの修復も試みましたが、エラーは見つかりませんでした。これに関するヘルプをいただければ幸いです。