Check if a navigation link exists or not in a sharepoint site (communication) using PowerShell

Hi !

I’m trying to check if a navigation link exists or not using PowerShell. If it detects it would reply yes or if it doesn’t then it would reply no.

This is what I came up after looking at examples.

Connect-PnPOnline -Url https://XXXajupeu.sharepoint.com/sites/test4
 
$navigationNodeCollection = Get-PnPNavigationNode -Location QuickLaunch 

if (Where-Object { $_.Title -eq "Pages" }) {
    Write-Host "yes it exists" -foregroundcolor DarkRed -backgroundcolor Red
}
else {
    Write-Host "no it doesn't" -foregroundcolor DarkRed -backgroundcolor Red
}

It doesn’t work, so if anyone have an answer please let me know.

Thanks!

If you want to check if the property Title of the object $navigationNodeCollection equals Pages you should change this →

if (Where-Object { $_.Title -eq "Pages" }) {

to that →

if ($($navigationNodeCollection.Title) -eq 'Pages') {
1 Like