Tuesday, 21 February 2017

Copy data from one column to another column


Write-host "Copying Data from abc to abc1"
Write-host "------"
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$WebSite = Read-host "Please enter the Site URL "
$ListName = Read-host "Please enter the Source List Name"
$SrcFieldName = Read-host "Please enter the Source Field Name to copy the data"
$DestFieldName = Read-host "Please enter the Destination Field Name to copy the data"

#Using Get-SPSite
function global:Get-SPSite($url)
 {
    return new-Object Microsoft.SharePoint.SPSite($url)
 }

Function global:Get-SPWeb($url)
{
  $site= New-Object Microsoft.SharePoint.SPSite($url)
        if($site -ne $null)
            {
               $web=$site.OpenWeb();
            }
    return $web
}

 #Parameters
 $web = Get-SPweb $WebSite
 $listName = $ListName

 #Use the Display Names
 $CopyFromColumnName = $SrcFieldName #"Claim" #column copy source
 $CopyToColumnName = $DestFieldName #"FEPClaims"  #destination column

  #Get the List
  $list = $web.lists[$ListName]

  #Get all Items
  $Items = $list.Items

#initialize count;
$Count=0

     foreach ($Item in $items)
        {
$Count++
            #copy data from one column to another
            $item[$copyToColumnName] = $item[$copyFromColumnName]

            #Do a system update to avoid Version and to Keep same metadata
            $item.SystemUpdate($false)
Write-Host $Count "record copied"
        }
Write-Host "Total " $Count "records copied."
Write-host "Completed copying of the records."
Write-host "------"


No comments:

Post a Comment