Here is my script for the above question, hope it will help other people who come across this same problem
function ProcessContentType($rootWeb, $ct, $fldLinks)
{
Write-Host "Finding this " $ct.Name " usage in this root web " $rootWeb.Title -ForegroundColor Magenta
$usages = [Microsoft.SharePoint.SPContentTypeUsage]::GetUsages($ct)
if($usages.Count -gt 0)
{
Write-Host "Total number of this content type usage: " $ct.Name " found in this root web " $rootWeb.Title " is " $usages.Count -ForegroundColor Magenta
foreach($usage in $usages)
{
if($usage.IsUrlToList -eq $true)
{
$subWebUrl = ""
if($usage.Url.ToLower().Contains("/pages"))
{
$subWebUrl = $usage.Url.ToLower().Replace("/pages", "")
$subWebUrl = $subWebUrl.Replace("/en", "")
$subWebUrl = $rootWeb.Url + $subWebUrl
}
$err = $null
$gc = Start-SPAssignment
$subWeb = $gc | Get-SPWeb $subWebUrl -erroraction SilentlyContinue -errorvariable err
if($err -ne $null)
{
Write-Host "The site " $usage.Url " could not be found " -ForegroundColor Red
}
if($subWeb -ne $null)
{
Write-Host "Site found " $subWeb.Url -ForegroundColor Green
$list = $subWeb.Lists["Pages"]
Write-Host "Number of content types found in this list " $list.Title " are : " $list.ContentTypes.Count
if($list.ContentTypes[$ct.Name] -ne $null)
{
$listContentType = $list.ContentTypes[$ct.Name]
write-host "Working on List Content type : " $listContentType.Name " in this list : " $list.Title
foreach($spFieldLink in $fldLinks)
{
write-host "Checking : " $spFieldLink.DisplayName " existence in this content type : " $listContentType.Name
if($listContentType.FieldLinks[$spFieldLink.Id] -eq $null)
{
write-host "The field : " $spFieldLink.DisplayName " does not exists yet in this content type : " $listContentType.Name
try
{
$listContentType.FieldLinks.Add($spFieldLink)
$listContentType.Update()
write-host "Field : " $spFieldLink.DisplayName "added to this content type : " $listContentType.Name -ForegroundColor Green
}
catch [Exception]
{
Write-Host "Adding Field : " $spFieldLink.DisplayName "to this content type : " $listContentType.Name ERROR! error $_.Exception.ToString() -ForegroundColor Red
}
}
else
{
write-host "The field : " $spFieldLink.DisplayName " ia already added to this list content type : " $listContentType.Name -ForegroundColor Green
}
}
}
else
{
write-host "The List Content type : " $ct.Name " does not exists in this list : " $list.Title
}
$subWeb.Dispose()
}
Stop-SPAssignment $gc
}
}
}
else
{
Write-Host "This content type usage: " + $ct.Name + " is not being used anywhere in this root web " + $rootWeb.Title -ForegroundColor Magenta
}
}
Using this script as the basis.
$site = Get-SPSite "http://sp2010"
$rootWeb = $site.RootWeb
$ct1 = $rootWeb.ContentTypes["Welcome Page"]
$ct2 = $rootWeb.ContentTypes["Tools Page"]
$ct = $ct1,$ct2
$spFieldLink = New-Object Microsoft.SharePoint.SPFieldLink ($rootWeb.Fields[[System.Guid]$field])
$fldLinks += @($spFieldLink)
ProcessContentType $rootWeb $ct $fldLinks
for the $field value, as you guys might have notice it is a guid field.
What I did was, first create all the columns that I wants to add to the content types and then use SharePoint Manager to get the ID of that columns.
Thanks.