locked
SharePoint 365 Online Using Powershell top add Links to Global Navigation Bar RRS feed

  • Question

  • I am trying to modify a PowerShell 5 script to add Links to the SharePoint 365 online Global Navigation bar of my sites. I currently have a script which will add a Header to the Global Navigation Bar, but rather than add headers, I need to modify it to add “Links”.

    Referencing the diagram below, I need the new link to appear as the example “Link1” Currently I can only add a header with the attached script which appears like the example “Hello1” below. Does anyone know how I can modify my script to make the Global Navigation item appear as a link?

    Script which adds a “Header” such as "Hello1" above:

    siteUrl = $_.Url

    $siteTitle = $_.Title

    $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)

    $context.Credentials = $credentials

    $context.RequestTimeOut = 5000 * 60 * 10;

    $web = $context.Web

    $site = $context.Site

    $context.Load($web)

    $context.Load($site)

    $context.ExecuteQuery() 

    $NavBar = $context.Web.Navigation.TopNavigationBar

    $NavigationNode = New-Object Microsoft.SharePoint.Client.NavigationNodeCreationInformation

    $NavigationNode.Title = $ItemName

    $NavigationNode.Url = $ItemUrlPath

    $NavigationNode.AsLastNode = $true          

    $context.Load($NavBar.Add($NavigationNode))

    $context.ExecuteQuery()  


    gm.ca

    Tuesday, February 9, 2016 2:34 PM

Answers

  • Hi,

    Sorry for the misunderstanding.

    From the documentation we can see that, the “TypeId” is “reserved for internal use and is not intended to be used directly from your code”:

    https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.navigationnodecreationinformation_members.aspx

    Also, there is no such properties to make a node we added to display like a “Link” currently.

    Thus, I would suggest you submit a feedback to the SharePoint UserVoice Platform if there any expectation about the future version of SharePoint Client API:

    http://sharepoint.uservoice.com/

    It is a place for customers provide feedback about Microsoft Office products. What’s more, if a feedback is high voted there by other customers, it will be promising that Microsoft Product Team will take it into consideration when designing the next version in the future.

    Best regards,

    Patrick


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Marked as answer by GMccracken.CA Friday, March 11, 2016 4:50 PM
    Friday, March 11, 2016 8:46 AM

All replies

  • Hi

    check this script from this blog

    $w = get-spweb http://takana
    $l = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode("Smells like team spirit", "/pages/teamspirit.aspx")
    $w.Navigation.TopNavigationBar.AddAsLast($l)

    http://chuvash.eu/2012/01/02/add-global-navigation-links-in-powershell/


    Kind Regards,

    John Naguib

    Senior Consultant

    John Naguib Blog John Naguib Twitter

    Please remember to mark this as answered if it helped you

    Wednesday, February 10, 2016 12:02 PM
  • Hi,

    Please update your script as below, it will add a link under the “Hello1” heading:

    $NavBar = $web.Navigation.TopNavigationBar 
    $context.Load($NavBar) 
    $context.ExecuteQuery()
    
    foreach ($node in $NavBar) 
    {
    	if($node.Title -eq "Hello1")
    	{
    		$NavNodes = $node.Children;
    		$context.Load($NavNodes) 
    		$context.ExecuteQuery() 
    
    		$NavigationNode = New-Object Microsoft.SharePoint.Client.NavigationNodeCreationInformation
    		$NavigationNode.Title = $ItemUrlName
    		$NavigationNode.Url = $ItemUrlPath
    		$NavigationNode.AsLastNode = $true            
    		$context.Load($NavNodes.Add($NavigationNode)) 
    		$context.ExecuteQuery() 
    	}
    }
    

    Best regards,

    Patrick

    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Proposed as answer by Dennis Guo Thursday, March 3, 2016 6:23 AM
    • Marked as answer by Patrick_Liang Friday, March 4, 2016 10:54 AM
    • Unmarked as answer by GMccracken.CA Thursday, March 10, 2016 1:33 PM
    Wednesday, February 24, 2016 5:25 AM
  • Thanks for the suggestions. Unfortunately they do not work for me: John, I cannot use get-spweb as this is an online Office 365 installation.

    Patrick, your script works but it does not add a link to the top level of the Navigation Bar, as in the screenshot I included with my posting. It creates a child link (Cookies) beneath the heading, Hello1. I have included the screenshot below:

    Please note that in my original screenshot the "Link" is at the same level as the Heading, which is what we need.

    Greg


    gm.ca


    Thursday, March 10, 2016 1:30 PM
  • I believe the solution I need is to assign a  TypeID to the NavigationNode which makes it a Link rather than a Header. The property exists but the shell does not accept

    $NavigationNode.TypeId = "7aaa605-79a9-whatever the code for a Link is"

    as a valid command, even though I can assign values to the other properties this way. Any ideas how to achieve this?


    When trying to assign the TypeId I get the following message indicating the field is a read-only value:



    Thursday, March 10, 2016 1:56 PM
  • Hi,

    Sorry for the misunderstanding.

    From the documentation we can see that, the “TypeId” is “reserved for internal use and is not intended to be used directly from your code”:

    https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.navigationnodecreationinformation_members.aspx

    Also, there is no such properties to make a node we added to display like a “Link” currently.

    Thus, I would suggest you submit a feedback to the SharePoint UserVoice Platform if there any expectation about the future version of SharePoint Client API:

    http://sharepoint.uservoice.com/

    It is a place for customers provide feedback about Microsoft Office products. What’s more, if a feedback is high voted there by other customers, it will be promising that Microsoft Product Team will take it into consideration when designing the next version in the future.

    Best regards,

    Patrick


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Marked as answer by GMccracken.CA Friday, March 11, 2016 4:50 PM
    Friday, March 11, 2016 8:46 AM
  • Thank you for that information and advice, Patrick.

    GM


    gm.ca

    Friday, March 11, 2016 4:50 PM