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.
  1. function GetNavigationInfo
  2. {
  3. param(
  4. [Parameter(Mandatory=$true, Position=0, ParameterSetName="web",
  5. ValueFromPipeline=$true,
  6. ValueFromPipelineByPropertyName=$true,
  7. HelpMessage="The SPWeb object to get navigation information for")]
  8. [Microsoft.SharePoint.SPWeb]$web
  9. )
  10. $NavXML = $web.Properties["_webnavigationsettings"];
  11. #write-host $NavXML -foreground yellow
  12. [xml]$file =[xml]$NavXML
  13. $xmlProperties = $file.WebNavigationSettings.SiteMapProviderSettings.TaxonomySiteMapProviderSettings|where {$_.name -eq "CurrentNavigationTaxonomyProvider"}
  14. $NavInfo = @{
  15. TermStoreId = $xmlProperties.TermStoreId
  16. TermSetId = $xmlProperties.TermSetId
  17. }
  18. return $NavInfo
  19. }
Usage
  1. $web = Get-SPWeb <weburl here>
  2. $NavInfo = GetNavigationInfo($web);
  3. $TaxSession = Get-SPTaxonomySession -Site $web.Site
  4. $TermStore = $TaxSession.TermStores[$NavInfo.TermStoreId]
  5. $TermSet = $TermStore.GetTermSet($NavInfo.TermSetId)