0

I have written a powershell script to go through all the sites in a site collection and pulling their quick nav bars. I would like to change the category names in the quick nav, not the links. Here is the code I have written to accomplish this part:

$quickLaunchCategory = $quickLaunch | where { $_.Title -eq $category }
$quickLaunchCategory.Title = $newTitle
$quickLaunchCategory.Update()

However this doesn't work. PowerShell claims that the property Title cannot be found for $quickLaunchCategory. I have also tried getting the members on $quickLaunchCategory but then I get the error that $quickLaunchCategory is not an object (however I can add links to it if I want to - so I am confused).

The question I have is, how do I change the title of a quick launch category?

1 Answer 1

1

I tried your script and I could successfully update navigation items.

So your problem can be:

  1. the "category" that you specified could not be found within navigation items. The result is that $quickLaunchCategory is NULL when you try to set the Title.
  2. you have multiple category with the same name, in that case you get a collection of navigation item

you can do a simple test to check if your category has been found or not and if you get only one or more results:

$quickLaunchCategory = $quickLaunch | where { $_.Title -eq $category }
if ($quickLaunchCategory -ne $nul)
{
    if ($quickLaunch.GetType().Name -eq "SPNavigationNodeCollection")
    {
        foreach ($currentNode in $quickLaunchCategory)
        {
            write-host "Multiple categories found for $($category)"
            $currentNode.Title = $newTitle
            $currentNode.Update()
            write-host "$($category) successfully updated to $($newTitle)"
        }
    }
    else
    {
        $quickLaunchCategory.Title = $newTitle
        $quickLaunchCategory.Update()
        write-host "$($category) successfully updated to $($newTitle)"
    }
}
else
{
    write-host "$($category) category could not be found"
}
1
  • You are correct in suggesting my problem was having multiple categories matching my search term. Excellent answer and great coding example by the way!
    – user5013
    Nov 20, 2015 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.