I am finding that there is so little information available online regarding PowerShell, CSOM and SharePoint online. I am stuck on a PowerShell problem for programmatically adding Child Links to the Global Navigation bar in our Online SharePoint 2013 (Office 365-Azure) site. I want to make it look like the global links in the attached image.
I have found code that works for me to add Headers, to my top link global navigation bar, but I cannot find anywhere, how to add children links under a given header on the global navigation bar. I am using CSOM libraries to do this. If there is a better way, please let me know.
While Googling, everything I have found either uses PS snapins from Sharepoint 2010 (which I cannot download and use in Sharepoint 2013 Online – unless someone knows  of a way to do that), or is written in C# or VB and I am unable translate the code into PowerShell.
Is there any chance that anyone would know how or be able to point me to a resource that would help me solve this issue? The following code snippets work well to add the top level links/headers to the global navigation bar for me but how to add sub links under these headers, programmatically using PowerShell v3.0?
I put the following in a foreach-object loop reading the information from an XML file…this all works well, for adding top level headers/links. I believe I just need to make slight alterations to this code to add sub-links under my global nav headings, but cannot figure out how:
Â
$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()
Hello Greg,
I have added a link parameter to the XML with Parent attribute .
[apcode language=”xml”]
<nav Url="https://tenant.sharepoint.com/sites/IT" Title="IT"> <link Url="https://tenant.sharepoint.com/sites/shalini2" Title="IT 1" Parent="IT"/> </nav>
[/apcode]
In the Powershell scriptÂ
[apcode language=”powershell”]
$Nodes = $Context.Web.Navigation.TopNavigationBar         $Context.Load($Nodes)         $Context.ExecuteQuery()          foreach ($node in $Nodes)         {          if($node.Title -eq $xmlNavs.Parent)          {           $NavNodes = $node.Children;           $Context.Load($NavNodes)           $Context.ExecuteQuery()            $NavigationNode = New-Object Microsoft.SharePoint.Client.NavigationNodeCreationInformation           $NavigationNode.Title = $xmlNavs.Title           $NavigationNode.Url = $xmlNavs.Url           $NavigationNode.AsLastNode = $true           $Context.Load($NavNodes.Add($NavigationNode))                            try                 {              $Context.ExecuteQuery()              CreateLogFile "Adding Link $($xmlNavs.Title) to Global Navigation Completed"                 }                 catch                 {                     CreateLogFile "Error Adding Link $($xmlNavs.Title) to Global Navigation $($_.Exception.Message)"                 }          }         }
[/apcode]