2

Based off of several blog posts I attempted the code below:

$n1 = New-Object -TypeName "Microsoft.SharePoint.Navigation.SPNavigationNode" -ArgumentList "People", "http://myURL", $true
$n1.properties["Target"] = "_blank"
$n1.Update()

This results in the error below with line 24 referencing the 2nd line of the code above.

Cannot index into a null array. At
Z:\myscripts\SearchDropdownMenuSetup.ps1:24 char:5
+ $n1.properties["Target"] = "_blank"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray

Is there any reason why I couldn't do this logic in PowerShell?

  • 1
    Can you post a link to one of the blogs? There really isn't a reason that wouldn't work in PowerShell, unless the SPNavigationNode class uses the HttpContext internally. From PowerShell the HttpContext will be blank. – beavel Feb 1 '14 at 14:13
2

This issue was resolved by adding the node to the SPWeb before updating the property:

Correct

$n1 = New-Object -TypeName "Microsoft.SharePoint.Navigation.SPNavigationNode" -ArgumentList "People", "http://myURL1", $true
$spWeb.Navigation.SearchNav.AddAsLast($n1)
$n1.properties["Target"] = "_blank"
$n1.Update()

Incorrect

$n1 = New-Object -TypeName "Microsoft.SharePoint.Navigation.SPNavigationNode" -ArgumentList "People", "http://myURL1", $true
$n1.properties["Target"] = "_blank"
$n1.Update()
$spWeb.Navigation.SearchNav.AddAsLast($n1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.