SOLVED

Error adding navigation link to SharePoint site

Brass Contributor

I have a powershell script that automates the creation of an Office 365 group and configures the associated SharePoint site.  The following code adds a link to the left navigation of the site. 

$ctx = Get-PnPContext;
$finalizeLinkAdded = $false;
try {
  $web = $ctx.Web
  $navColl = $web.Navigation.QuickLaunch
  $ctx.Load($navColl) ;       
  $ctx.ExecuteQuery();

  $newNavNode = New-Object Microsoft.SharePoint.Client.NavigationNodeCreationInformation
  $newNavNode.Title = "Link Title"
  $newNavNode.Url = $linkToAdd
  $newNavNode.AsLastNode = $true

  $navColl.Add($newNavNode) | out-null;

  $web.Update();
  $ctx.ExecuteQuery();
  $finalizeLinkAdded = $true;
}
catch {
  $_
}

I have connected to the site using connect-pnponline (not shown in the snippet below).  This works fine when I run the script from my console.  However, this script is called using a job.

$job = Start-Job -InitializationScript { d:\powershell\assemblies.ps1}  -ScriptBlock { d:\powershell\create-navigation.ps1 } 

When the script is called this way, I get a weird error.

Cannot convert argument "parameters", with value: "Microsoft.SharePoint.Client.NavigationNodeCreationInformation", 
for "Add" to type "Microsoft.SharePoint.Client.NavigationNodeCreationInformation": 
"Cannot convert the "Microsoft.SharePoint.Client.NavigationNodeCreationInformation" value 
of type "Microsoft.SharePoint.Client.NavigationNodeCreationInformation" to 
type "Microsoft.SharePoint.Client.NavigationNodeCreationInformation"."

Am I missing something?

1 Reply
best response confirmed by Robbert van Andel (Brass Contributor)
Solution

I ended up posting this somewhere else thinking it was deleted since I didn't see it after posting.  The answer was simple

 

Add-PnPNavigationNode -Location "QuickLaunch" -Title "Link" -url $Linkurl
1 best response

Accepted Solutions
best response confirmed by Robbert van Andel (Brass Contributor)
Solution

I ended up posting this somewhere else thinking it was deleted since I didn't see it after posting.  The answer was simple

 

Add-PnPNavigationNode -Location "QuickLaunch" -Title "Link" -url $Linkurl

View solution in original post