Copy data from one list to another list in SharePoint using PowerShell

Advertisements
In this article we are copying values from one list to another list in SharePoint using PowerShell
In both list having field “uniqueid” , using the “uniqueid” only I am updating values from LISTB to LISTA. In LISTB having more fields we need to copy the value from LISTB to LISTA , using camel query we are getting the value from LISTA in to this variable “$item['uniqueid']” and in FieldRef Name  we have to give the LISTB  field name.
Below is the script to update the items.

Add-PSSnapin Microsoft.sharepoint.powershell
      $web =  Get-SPWeb "http://dotnetsharepoint.com /sites/sharepoint/"
      write-host $web
    $Source =$web.Lists["LISTA"]           
     $Dest = $web.lists["LISTB”]
     write-host = $Source
     Write-host = $Dest
                            
    $items = $Source.items
    foreach ($item in $items) {
  
      $camlQuery ="<Where><Eq><FieldRef Name='uniqueid' /><Value Type='Text'>"+$item['uniqueid']+"</Value></Eq></Where>"
        $spQuery = new-object Microsoft.SharePoint.SPQuery
        $spQuery.Query = $camlQuery
        $spQuery.RowLimit = 1
        #check if the item is already present in destination list
         $ditems =  $Dest.GetItems($spQuery)
             $item["UserName"] = $ditems[0]["UserName"] 
 $modifiedBy = $item["Editor"]
$modifieddate =$item["Modified"]
Write-Host $item.ID
$item["Editor"] = $modifiedBy
$item["Modified"] = $modifieddate
$item.Update()
$Source.Update()
#Write-Host $count+1
        }

SharePoint Online Real Time Training Contact: JLAKSHMITULASI@GMAIL.COM
Advertisements
SHARE

lakshmitulasi Jasti

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment