Keep in mind though: ReadOnly fields, such as [CreatedDateTime] or [LastUpdatedDateTime] field, cannot be manipulated through the script below.
try { $web = Get-SPWeb "http://site" $sList = $web.Lists["Movies2"] #source-list $dList = $web.Lists["Movies"] #destination-list Write-Host "Working on Web: "$web.Title -ForegroundColor Green if($sList) { Write-Host " Working on List: " sList.Name -ForegroundColor Cyan $spSourceItems = $sList.Items $sourceSPFieldCollection = $sList.Fields foreach($item in $spSourceItems) { if($dList) { $newSPListItem = $dList.AddItem() #Copy all field data except Attachments foreach($spField in $sourceSPFieldCollection) { if($spField.ReadOnlyField -ne $True -and $spField.InternalName -ne "Attachments") { $newSPListItem[$($spField.InternalName)] = $item[$($spField.InternalName)] } } #Copy Attachments foreach($leafName in $item.Attachments) { $spFile = $sList.ParentWeb.GetFile($($item.Attachments.UrlPrefix + $leafName)) $newSPListItem.Attachments.Add($leafName, $spFile.OpenBinary()) } #Update new LisItem $newSPListItem.Update() } Write-Host " Copying $($item["Name"]) completed" } } } catch { Write-Host "Error: " $_.Exception.ToString() -ForegroundColor Red }
No comments:
Post a Comment