Sunday, March 23, 2014

Sharepoint Powershell - Copy Column (Fields) to list

$web = Get-SPWeb http://siteURL           
$sourcelist = $web.Lists["SourceList"]
$destlist = $web.Lists["DetinationList"]

$columns=$sourcelist.fields



foreach($col in $columns)
{
 if( $destlist.fields.ContainsField($col))
               {                                      
           # Write-Host "found" $col
               }
               else
               {
              Write-Host "Field not found ="     $col, $col.Type
              Write-Host "Adding Field" 
              $destlist.fields.Add($col)
               }


}

Write-Host "Script Completed" 

No comments:

Post a Comment