Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add-PSSnapin "Microsoft.SharePoint.Powershell –ErrorAction SilentlyContinue
#Variables start
$siteUrl = "http://intranet.ul.com/
$termSetStoreDesc = "Managed Metadata Service
$groupDesc = "SDC
$termSetName = "Geographies
$saveLoc = "D:\MigrationScripts\MMS\TermsSets_GUIDs\SDCXML.xml
$session = new-object Microsoft.SharePoint.Taxonomy.TaxonomySession($siteUrl)
#Variables end
$XML = "<?xml version='1.0'?>
$termStore = $session.TermStores[$termSetStoreDesc]
$XML += "<TermStore Name='" + $termStore.Name + "' GUID='" + $termStore.ID + "'>
$group = $termStore.Groups[$groupDesc]
$XML += "<Group Name='" + $group.Name + "' GUID='" + $group.ID + "'>
$termSet = $group.TermSets[$termSetName]
$XML += "<TermSetGroup Name='" + $termSet.Name + "' GUID=' + $termSet.ID + "'>
$terms = $termSet.GetTerms(200)
function RenderTerm($term)
{
$result = "<Term><Name> + $term.Name + "</Name><GUID> + $term.ID + "</GUID>
If ($term.TermsCount –gt 0)
{
$result += "<ChildTerms>
Foreach ($childTerm in $term.Terms)
{
$result += RenderTerm($childTerm)
}
$result += "</ChildTerms>
}
$result += "</Term>
return $result
}
Foreach ($term in $terms)
{
$XML += RenderTerm($term)
}
$XML += "</TermSet></TermSetGroup></TermStore>
$XML | out-File –FilePath $saveLoc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment