Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 34890

SharePoint – create MMS column from PowerShell

$
0
0

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables
$WebURL="http://site1.sp.com/"
$ListName="DL"
$FieldName="TempMMSField"

#taxonomy related variables
$termStoreName = "Managed Metadata Service"
$termStoreGroup = "Global Terms"
$termSetName = "Topic"

#Get the web and List
$Web = Get-SPWeb $WebURL
$List = $Web.Lists[$ListName]

#Check if the column with same name exists in the list
if(!($List.Fields.ContainsField($FieldName)))
{
#Get the Termset from Term store
$TaxonomySession = Get-SPTaxonomySession -Site $web.Site
$TermStore = $TaxonomySession.TermStores[$termStoreName]
$TermGroup = $TermStore.Groups[$termStoreGroup]
$TermSet = $TermGroup.TermSets[$termSetName]

#Form the Taxonomy Field
$TaxonomyField = $List.Fields.CreateNewField("TaxonomyFieldType", $TermSet.Name)
$TaxonomyField.SspId = $TermSet.TermStore.Id
$TaxonomyField.TermSetId = $TermSet.Id

#Add the field to List
$List.Fields.Add($TaxonomyField)
$List.Update()

Write-host "Managed Metadata column Added successfully!"
}
else
{
Write-host "Managed Metadata column with the specific name already exists!" -f RED
}

 


Viewing all articles
Browse latest Browse all 34890

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>