Last active
August 29, 2015 14:21
-
-
Save ryanjonhealy/44a7b4fa126bf4649ae5 to your computer and use it in GitHub Desktop.
Create SP Sites based on Term Store
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$web = get-spweb http://sp2013/sites/Root #Change to your site URL | |
$template = $web.GetAvailableWebTemplates(1033) | Where-Object {$_.Title -eq “TemplateSite”} #Change to your template name | |
$SiteCollection = Get-SPSite http://sp2013/sites/Root #Change to your site URL | |
#Get the Term Store ID | |
$TaxSession = Get-SPTaxonomySession -Site $SiteCollection | |
$TermStore = $TaxSession.TermStores[“Managed Metadata Service”] #Change to your service name | |
$TermStore.Id | |
#Get the Term Set | |
$TermStoreGroup = $TermStore.Groups[“Functions”] #Change to your Terms Store group name -the main parent term | |
$TermSetList = $TermStoreGroup.TermSets | |
#create an array | |
$myArray = $TermSetList.Terms | |
foreach ($element in $myArray) | |
{ | |
write-host $element.name -ForegroundColor Magenta #writes the term | |
$NewSiteUrl = $web + "/" + $element.name | |
write-host $NewSiteUrl -ForegroundColor green #writes the new sites url | |
#check if it already exists | |
$exists = Get-SPWeb -Identity $NewSiteUrl -ErrorAction SilentlyContinue | Select-Object -Property Exists -ErrorAction SilentlyContinue | |
if($exists -eq $null) | |
{ | |
#create the new site | |
$newweb = New-SPWeb -Url $NewSiteUrl -Name $element.name -AddToTopNav -UseParentTopNav | |
#apply your template | |
$newweb.ApplyWebTemplate($template.Name) | |
write-host "Created" -ForegroundColor green | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment