I am using this code for it but I am unable to get the hierarchy which I got from the file....
$taxonomySite = Get-SPSite http:url
$taxonomySession = Get-SPTaxonomySession -site $taxonomySite
$termStore = $taxonomySession.TermStores["Managed Metadata Service"]
write-host “Connection made with term store -”$termStore.Name
$termStoreGroup = $termStore.CreateGroup(“General Business Taxonomy”)
$termStoreGroup.Description = “General Business Terms”
$termStoreGroup.AddGroupManager(“x\y”)
$termStoreGroup.AddContributor(“x\y”)
$termSet = $termStoreGroup.CreateTermSet("General Business Taxonomy")
$data = Import-Csv "C:\terms.csv"
foreach ($line in $data)
{
$TermName = $line."Level 1 Term"
$Termvalue =$line."Level 2 Term"
$Termvalue =$line."Level 3 Term"
$Termvalue =$line."Level 4 Term"
$Termvalue =$line."Level 5 Term"
if ($termSet.Terms[$TermName] -eq $Null)
{
if($TermName -ne "")
{
$term = $termSet.CreateTerm($TermName, 1033)
Write-Host -ForegroundColor Cyan "Added term $TermName"
$termStore.CommitAll()
}
}
if ($termSet.Terms[$TermName] -ne $Null)
{
$mainterm = $termSet.Terms[$TermName]
if($TermValue -ne "")
{
$subterm = $mainterm.CreateTerm($TermValue, 1033)
Write-Host -ForegroundColor Cyan "Added sub term $TermValue"
$termStore.CommitAll()
}
}
}
$termStore.CommitAll()