Creating global navigation w Powershell and SharePoint 2010

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 3 months ago.

  • Author
    Posts
  • #6422

    by Morpheus at 2013-03-24 11:39:31

    I got this script intended to create a Horizontal Global Navigation through PowerShell. Something is wrong. After running the script I can only see the first group in the navigation list. Can anyone help to correct it?

    [code2=powershell]$siteCollectionUrl = "http://contoso.com:7050"

    $rootSiteCollection = Get-SPSite $siteCollectionUrl

    if ($rootSiteCollection -ne $null)
    {
    $rootWeb = $rootSiteCollection.RootWeb
    $navList = $rootWeb.Lists.TryGetList("GlobalNavigation")
    if ($navList -ne $null)
    {
    $newItem = $navList.AddItem()
    $newItem["Title"] = "Sites"
    $newItem["CC_NavigationUrl"] = "/"

    $newItem.Update()

    Write-Host "Root Site Collection Added"

    $newItem = $navList.AddItem()
    $newItem["Title"] = "Group 1"
    $newItem["CC_NavigationUrl"] = "/sites/group1"

    $newItem.Update()

    Write-Host "Group Site Collection Added"

    $newItem = $navList.AddItem()
    $newItem["Title"] = "Group 2"
    $newItem["CC_NavigationUrl"] = "/sites/group2"

    $newItem.Update()

    Write-Host "Group Site Collection Added"

    $newItem = $navList.AddItem()
    $newItem["Title"] = "Group 3"
    $newItem["CC_NavigationUrl"] = "/sites/group3"

    $newItem.Update()

    Write-Host "Group Site Collection Added"

    $child = $navList.AddItem()
    $child["Title"] = "Subsite 1"
    $child["CC_NavigationUrl"] = "/sites/sub1"
    $child["CC_NavigationParent"] = $newItem

    $child.Update()
    Write-Host "Sub Site Added"

    $child = $navList.AddItem()
    $child["Title"] = "Subsite 2"
    $child["CC_NavigationUrl"] = "/sites/sub2"
    $child["CC_NavigationParent"] = $newItem

    $child.Update()
    Write-Host "Sub Site Added"

    $child = $navList.AddItem()
    $child["Title"] = "Subsite 3"
    $child["CC_NavigationUrl"] = "/sites/sub3"
    $child["CC_NavigationParent"] = $newItem

    $child.Update()
    Write-Host "Sub Site Added"
    }

    if ($rootWeb -ne $null)
    {
    $rootWeb.Dispose()
    }
    }

    if ($rootSiteCollection -ne $null)
    {
    $rootSiteCollection.Dispose()
    }[/code2]

    by DonJ at 2013-03-24 18:12:04

    I'm not a SharePoint person, but it's possible that it isn't liking you re-using $newItem? That is, as a test, if you took the second block and changed the variable to $newItem2, does it make any difference?

    by Morpheus at 2013-03-25 00:20:34

    DonJ, I Tried it, but it does not make any difference

    by DonJ at 2013-03-25 06:29:31

    I don't see any logic problems in your script, so unfortunately it's something in the way SP is processing the data that I'm not seeing. Let's see if anyone else has anything to offer.

You must be logged in to reply to this topic.