How to get all the links from the top link bar using powershell

I have a root site and three subsites. The three subsite links are added to the top link bar and here we are going to retrieve all the links available in the top link bar using powershell.


TopLinkBar.png



$site=Get-SPSite "
http://serverName:1111/sites/sample"
$web=$site.OpenWeb()
$nodeColl = $web.Navigation.TopNavigationBar
foreach ($node in $nodeColl)
{
  write-host $node.Title
}