Below is the powershell command to add Navigation links in SharePoint.This was tested in SharePoint 2013 environment.This script will check if the link is present in the site if not it will add the links along with audience targeting
$snapin = Get-PSSnapin | Where-Object { $_.Name -eq "Microsoft.SharePoint.Powershell" }
if ($snapin -eq $null) {
Write-Host "[INIT] Loading SharePoint Powershell Snapin"
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
$Web = Get-SPWeb http://testWebapplication:7777
$TopNav = $Web.Navigation.TopNavigationBar
Write-Host -ForegroundColor Green "Creating Navigation links ......................."
$Heading = $TopNav | where { $_.Title -eq "Link1" }
if($Heading -eq $null)
{
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Link1", "/Lists/CreateNewPublication/DocProjects.aspx");
$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)
$Web.Update()
}
$Heading = $TopNav | where { $_.Title -eq "Search" }
if($Heading -eq $null)
{
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Search", "/SitePages/Search.aspx");
$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)
$Web.Update()
}
$Heading = $TopNav | where { $_.Title -eq "Google" }
if($Heading -eq $null)
{
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Google", http://www.google.com);
$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)
$Web.Update()
}
$Heading = $TopNav | where { $_.Title -eq "Yahoo" }
if($Heading -eq $null)
{
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Yahoo", http://yahoo.co.in);
$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)
$Heading.Properties["Audience"] = ";;;;" + "IK,IL,R,C"
$Heading.update()
$Web.Update()
}
$Heading = $TopNav | where { $_.Title -eq "Reports" }
if($Heading -eq $null)
{
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Reports", "/SitePages/Reports.aspx");
$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)
$Heading.Properties["Audience"] = ";;;;" + "PM,TL,IL,C"
$Heading.update()
$Web.Update()
} $Heading = $TopNav | where { $_.Title -eq " Help" }
if($Heading -eq $null)
{
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @(" Help", "/Lists/HelpLibrary ");
$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)
$Web.Update()
}
Write-Host -ForegroundColor Green "Navigation link creation completed"
Pause
$snapin = Get-PSSnapin | Where-Object { $_.Name -eq "Microsoft.SharePoint.Powershell" }
if ($snapin -eq $null) {
Write-Host "[INIT] Loading SharePoint Powershell Snapin"
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
$Web = Get-SPWeb http://testWebapplication:7777
$TopNav = $Web.Navigation.TopNavigationBar
Write-Host -ForegroundColor Green "Creating Navigation links ......................."
$Heading = $TopNav | where { $_.Title -eq "Link1" }
if($Heading -eq $null)
{
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Link1", "/Lists/CreateNewPublication/DocProjects.aspx");
$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)
$Web.Update()
}
$Heading = $TopNav | where { $_.Title -eq "Search" }
if($Heading -eq $null)
{
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Search", "/SitePages/Search.aspx");
$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)
$Web.Update()
}
$Heading = $TopNav | where { $_.Title -eq "Google" }
if($Heading -eq $null)
{
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Google", http://www.google.com);
$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)
$Web.Update()
}
$Heading = $TopNav | where { $_.Title -eq "Yahoo" }
if($Heading -eq $null)
{
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Yahoo", http://yahoo.co.in);
$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)
$Heading.Properties["Audience"] = ";;;;" + "IK,IL,R,C"
$Heading.update()
$Web.Update()
}
$Heading = $TopNav | where { $_.Title -eq "Reports" }
if($Heading -eq $null)
{
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Reports", "/SitePages/Reports.aspx");
$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)
$Heading.Properties["Audience"] = ";;;;" + "PM,TL,IL,C"
$Heading.update()
$Web.Update()
} $Heading = $TopNav | where { $_.Title -eq " Help" }
if($Heading -eq $null)
{
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @(" Help", "/Lists/HelpLibrary ");
$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)
$Web.Update()
}
Write-Host -ForegroundColor Green "Navigation link creation completed"
Pause
These include features like FlashFill data pattern recognition, Slicers to provide customized data filtering options, and more. SharePoint Intranet
ReplyDeleteI have a powershell script to add headers and links to Sharepoint o365, but I cannot set the audience for the link in the script like you have done here.
ReplyDeleteIs it possible to do for O365?