Problem with a command PnP

Hi there !

I’m very new to powershell and i have problem with a command. I’m trying to remove a link from the navigation bar of my sharepoint site using powershell. I found a site and copied the commands, but one command isn’t working, I tried searching to find a way to fix it and i found the pnp website, i read it but didn’t understand much, that’s why i came here for help.

Commands :

Connect-PnPOnline -Url https://XXX.sharepoint.com/sites/test10
$navigationNodeCollection = Get-PnPNavigationNode -Location TopNavigationBar
$navigationNode = $navigationNodeCollection | Where-Object { $_.Title -eq "Pages" }
Remove-PnPNavigationNode -Identity $navigationNode.Id -Force                       # $navigationNode.Id isn't working

Thank you !

Again … when you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink:

You forgot to ask a question. :wink: And …

… is not helpful at all. What happens? Do you get error messages? If yes - please share them here completely (formatted as code as well please)

My appologies for not formatting the right way.

I got this error :

Remove-PnPNavigationNode : Impossible de lier l'argument au paramètre « Identity », car il a la valeur Null.
Au caractère Ligne:4 : 36
+ Remove-PnPNavigationNode -Identity $navigationNode.Id -Force # $navig ...
+                                    ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData : (:) [Remove-PnPNavigationNode], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,PnP.PowerShell.Commands.Branding.RemoveNavigationNode

Sorry if it’s in another language, i’m using a laptop from work

The error message is pretty obvious though. $navigationNode.Id seems to empty. And since you’re not showing how you populate this variable all we could do is taking a wild guess. :man_shrugging:t4:

1 Like

Hi,
Check what you have in $navigationNode after running the script.
If it is empty, remove | Where-Object { $_.Title -eq “Pages” } and then check, what do you have in $navigationNode. If in output you will have list of pages you should use | Where-Object { $_.Title -like “*Pages*” } to get only pages with Pages in name.

1 Like

I found the solution. In the site I visited to get the script, it didn’t specify that the script only works on only team sites. My site is a communication site so I had to change the location :

$navigationNodeCollection = Get-PnPNavigationNode -Location TopNavigationBar

To :

$navigationNodeCollection = Get-PnPNavigationNode -Location QuickLaunch

I found the problem by checking the output, the output was always empty every time I executed the script so i figured that it was the wrong location. Thanks a lot!

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink: