I was working with managed navigation for a web site. I needed to get the navigation termstore and navigation termset ids for the web site. We had a choice to hard-code these parameters or to get it as a user input. But we can easily get these values from the SPWeb object properties. Following PowerShell function would return a custom PowerShell object with these properties.
- function GetNavigationInfo
- {
- param(
- [Parameter(Mandatory=$true, Position=0, ParameterSetName="web",
- ValueFromPipeline=$true,
- ValueFromPipelineByPropertyName=$true,
- HelpMessage="The SPWeb object to get navigation information for")]
- [Microsoft.SharePoint.SPWeb]$web
- )
- $NavXML = $web.Properties["_webnavigationsettings"];
- #write-host $NavXML -foreground yellow
- [xml]$file =[xml]$NavXML
- $xmlProperties = $file.WebNavigationSettings.SiteMapProviderSettings.TaxonomySiteMapProviderSettings|where {$_.name -eq "CurrentNavigationTaxonomyProvider"}
- $NavInfo = @{
- TermStoreId = $xmlProperties.TermStoreId
- TermSetId = $xmlProperties.TermSetId
- }
- return $NavInfo
- }
Usage
- $web = Get-SPWeb <weburl here>
- $NavInfo = GetNavigationInfo($web);
- $TaxSession = Get-SPTaxonomySession -Site $web.Site
- $TermStore = $TaxSession.TermStores[$NavInfo.TermStoreId]
- $TermSet = $TermStore.GetTermSet($NavInfo.TermSetId)