Get all Metadata Columns using PowerShell, this will come handy when you need to know the column details.
Add-PsSnapin Microsoft.SharePoint.PowerShell
function GetMapping($site, $MMSField, $Field, $ContentTypes)
{
$taxonomySession = Get-SPTaxonomySession -Site $site
$termStore = $taxonomySession.TermStores["Managed Metadata CTH"]
$MMSGroup = $termStore.Groups["Global Taxonomy"]
$termset = $MMSGroup.TermSets[$MMSField.TermSetId]
Write-Host "Site Column Name : "$Field.Title
Write-Host "MMS Column Name : "$MMSField.Title
Write-Host "Termsset ID : "$termset.id
Write-Host "Termset Name : "$termset.Name
Write-Host "Content Types : "$ContentTypes
Write-Host "--------------------------------------------------------"
}
function GetAllMetadataColumns($url)
{
$site = new-object Microsoft.SharePoint.SPSite($url)
$SiteColumns = $site.rootweb.Fields
$Spsite = get-spsite $url
$web = $Spsite.OpenWeb()
ForEach ($SiteCol in $SiteColumns)
{
if($SiteCol.Group -eq "ABC CTH Columns" -and $SiteCol.Type -eq "Invalid" )
{
$ContentTypeNames = ""
foreach ($contenttype in $web.ContentTypes)
{
foreach ($field in $contenttype.Fields)
{
if ($field.get_InternalName() -eq $SiteCol.InternalName)
{
#write-host $contenttype.Name
$ContentTypeNames = $ContentTypeNames + $contenttype.Name + ", "
}
}
}
$Mfield = [Microsoft.SharePoint.Taxonomy.TaxonomyField] $SiteCol
if($Mfield -ne $null)
{
GetMapping $site $Mfield $SiteCol $ContentTypeNames
}
}
}
$site.Dispose()
}
GetAllMetadataColumns "http://sharepoint"