First, we will assign the site that contains the list to a variable and use this variable to get the list:
#Get Web and List objects
$web = Get-SPWeb http://portal/permuniquesite
$list = $web.Lists["Shared Documents"]
Next, we will get the current metadata navigation settings for the list and assign them to a variable:
#Get metadata navigation settings for the list
$listNavSettings = [Microsoft.Office.DocumentManagement.MetadataNavigation.MetadataNavigationSettings]::GetMetadataNavigationSettings($list)
The next two lines of the script clear the configured hierarchies and configured key filters on the list. You could use these commands in combination with the SetMetadataNavigationSettings and $list.RootFolder.Update() commands mentioned later to remove any currently configured metadata navigation settings for the list:
#Clear current metadata navigation settings on the list
$listNavSettings.ClearConfiguredHierarchies()
$listNavSettings.ClearConfiguredKeyFilters()
These commands will add my two custom columns to the Selected Key Filter Fields:
#Configure key filters by adding columns
$listNavSettings.AddConfiguredKeyFilter($list.Fields["Technology"])
$listNavSettings.AddConfiguredKeyFilter($list.Fields["Document Status"])
These next two lines are quite important. I have found that the navigation hierarchy configuration does not work when configuring it from PowerShell unless you add the default Folders item to the Selected Hierarchy Fields first. Without this step, the custom columns will be added successfully in the Metadata navigation settings page, but they will not appear in the Tree View interface:
#Add folder navigation hierarchi$listes into list settings
#This is required to enable and show navigation hierarchies in the Tree View
$folderHierarchy = [Microsoft.Office.DocumentManagement.MetadataNavigation.MetadataNavigationHierarchy]::CreateFolderHierarchy()
$listnavSettings.AddConfiguredHierarchy($folderHierarchy)
The next step is optional, but contains the commands needed to add Content Type navigation hierarchies to the settings, if required:
#Optionally add content type navigation hierarchies into list settings if required
$ctHierarchy = [Microsoft.Office.DocumentManagement.MetadataNavigation.MetadataNavigationHierarchy]::CreateContentTypeHierarchy()
$listnavSettings.AddConfiguredHierarchy($ctHierarchy)
We now add the custom columns to the Selected Hierarchy Fields:
#Configure extra navigation hierarchies by adding list columns
$listNavSettings.AddConfiguredHierarchy($list.Fields["Technology"])
$listNavSettings.AddConfiguredHierarchy($list.Fields["Document Status"])
And finally, set the metadata navigation settings and update the root folder of the list, which is where the settings are stored:
#Set the new metadata navigation settings and update the root folder of the list
[Microsoft.Office.DocumentManagement.MetadataNavigation.MetadataNavigationSettings]::SetMetadataNavigationSettings($list, $listNavSettings, $true)
$list.RootFolder.Update()
#Get Web and List objects
$web = Get-SPWeb http://portal/permuniquesite
$list = $web.Lists["Shared Documents"]
Next, we will get the current metadata navigation settings for the list and assign them to a variable:
#Get metadata navigation settings for the list
$listNavSettings = [Microsoft.Office.DocumentManagement.MetadataNavigation.MetadataNavigationSettings]::GetMetadataNavigationSettings($list)
The next two lines of the script clear the configured hierarchies and configured key filters on the list. You could use these commands in combination with the SetMetadataNavigationSettings and $list.RootFolder.Update() commands mentioned later to remove any currently configured metadata navigation settings for the list:
#Clear current metadata navigation settings on the list
$listNavSettings.ClearConfiguredHierarchies()
$listNavSettings.ClearConfiguredKeyFilters()
These commands will add my two custom columns to the Selected Key Filter Fields:
#Configure key filters by adding columns
$listNavSettings.AddConfiguredKeyFilter($list.Fields["Technology"])
$listNavSettings.AddConfiguredKeyFilter($list.Fields["Document Status"])
These next two lines are quite important. I have found that the navigation hierarchy configuration does not work when configuring it from PowerShell unless you add the default Folders item to the Selected Hierarchy Fields first. Without this step, the custom columns will be added successfully in the Metadata navigation settings page, but they will not appear in the Tree View interface:
#Add folder navigation hierarchi$listes into list settings
#This is required to enable and show navigation hierarchies in the Tree View
$folderHierarchy = [Microsoft.Office.DocumentManagement.MetadataNavigation.MetadataNavigationHierarchy]::CreateFolderHierarchy()
$listnavSettings.AddConfiguredHierarchy($folderHierarchy)
The next step is optional, but contains the commands needed to add Content Type navigation hierarchies to the settings, if required:
#Optionally add content type navigation hierarchies into list settings if required
$ctHierarchy = [Microsoft.Office.DocumentManagement.MetadataNavigation.MetadataNavigationHierarchy]::CreateContentTypeHierarchy()
$listnavSettings.AddConfiguredHierarchy($ctHierarchy)
We now add the custom columns to the Selected Hierarchy Fields:
#Configure extra navigation hierarchies by adding list columns
$listNavSettings.AddConfiguredHierarchy($list.Fields["Technology"])
$listNavSettings.AddConfiguredHierarchy($list.Fields["Document Status"])
And finally, set the metadata navigation settings and update the root folder of the list, which is where the settings are stored:
#Set the new metadata navigation settings and update the root folder of the list
[Microsoft.Office.DocumentManagement.MetadataNavigation.MetadataNavigationSettings]::SetMetadataNavigationSettings($list, $listNavSettings, $true)
$list.RootFolder.Update()