0

I'm trying to add a menu-item in my PowerShell ISE by using this tutorial.

Function My-Custom-Function { 
    Write-Host “Running my very own function!” 
}

$psISE.CustomMenu.Submenus.Add(“Run Custom Function”, {My-Custom-Function}, “Shift+Ctrl+f”)

But for some reason I get this error:

You cannot call a method on a null-valued expression.
At line:5 char:31
+ $psISE.CustomMenu.Submenus.Add <<<< (“Run Custom Function”, {My-Custom-Function}, “Shift+Ctrl+f”)
    + CategoryInfo          : InvalidOperation: (Add:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

I run Windows 7 Enterprise and I run the PowerShell ISE as Administrator...

Any thoughts about this issue?

Michiel
  • 7,855
  • 16
  • 61
  • 113

2 Answers2

0

Try This

Function My-Custom-Function { Write-Host “Running my very own function!” }

$psISE.CurrentPowerSHellTab.AddOnsMenu.Submenus.Add(“Run Custom Function”, {My-Custom-Function}, "Shift+Ctrl+f")

This works for V3 on my system!!

Thomas Lee
  • 1,158
  • 6
  • 13
0

The text:

$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add(“Run Custom Function”, {My-Custom-Function}, "Shift+Ctrl+f")

could better be changed to

$psISE.PowerShellTabs.AddOnsMenu.Submenus.Add(“Run Custom Function”, {My-Custom-Function}, "Shift+Ctrl+f")

Assuming you want the add-on menu for all PowerShell tabsl

Thomas Lee
  • 1,158
  • 6
  • 13