Write-host "Copying Data from abc to defs field"
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)
{
if($item["Content Type"] -eq "Content type name")
{
Write-Host "The Content Type is: " $item["Content Type"]
$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 "------"
Ref: https://shipoint.com/2013/02/25/find-and-replace-content-types-in-sharepoint-2010-using-powershell/
No comments:
Post a Comment