December 6, 2016

// // Leave a Comment

Create multiple top navigation with CSV data source using Powershell script

1) In this post we will see how to create the top navigation with CSV File as data source using powershell script

2) Also refer below powershell scripts

Bulk Creation of Site Columns:

Bulk Creation of Site Content Types:

Bulk Lists and Libraries in SharePoint

Bulk File upload to sharepoint library

Create multiple columns inside SharePoint List using Powershell

Upload List Template and Create List based on List Template using PowerShell

3) Create a CSV File like below

4) Create a script using below code
#Author: Prem Kumar
#Date: Feb 11 2015

    [string]$subsiteurl = $(Read-Host -prompt "Enter Web Application Root URL...?"),
    [string]$CsvFilePath = $(Read-Host -prompt "Enter the CSV"),

Function Set-SPGlobalNav {

    [Parameter(Mandatory=$true, ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$True)]
    BEGIN {
        Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
        $web = $site.Read() 
        $CreateNavigationNodeMethod = [Microsoft.SharePoint.Publishing.Navigation.SPNavigationSiteMapNode]::CreateSPNavigationNode
        write-host "nAdding the Heading Node:  $Heading"
        $headingNode = $CreateNavigationNodeMethod.Invoke($Heading, [System.String]::Empty, [Microsoft.SharePoint.Publishing.NodeTypes]::Heading, $web.Navigation.TopNavigationBar)
        $headingCollection = $headingNode.Children   
        $inputFile = Import-CSV $Links
        foreach($row in $inputFile) {
           write-host "Adding the Link:  $row.LinkTitle"
            $linkNode = $CreateNavigationNodeMethod.Invoke($row.LinkTitle, $row.LinkURL, [Microsoft.SharePoint.Publishing.NodeTypes]::AuthoredLinkPlain, $headingCollection)

$web = Get-SPWeb $subsiteurl
$SPPubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$SPPubWeb.Navigation.InheritGlobal = $false
$SPPubWeb.Navigation.GlobalIncludeSubSites = $true
$SPPubWeb.Navigation.GlobalIncludePages = $false
#Deletes old navigation data
$nodeColl = $web.Navigation.TopNavigationBar
while($count -ne 0)
$nav_1= $CsvFilePath+"\Navigation.csv"
Set-SPGlobalNav -Site $web -Heading "TopHeader" -Links $nav_1


Post a Comment