Thanks to Shay Levi and Jaykul it became a nice advanced function with parametersets.
You can find the code in the ISE-Cream project
Just when I finished writing the header comments Ravi wanted to use the function not restricted to toplevel menu items.
First attemps tried to search the tree, but there can be more subitems with the same name hidden in the menu structure. To get it clear I designed the following function, which requires the complete path to the item to delete:
function Remove-IseMenuItem {
$submenu = $psise.CurrentPowerShellTab.AddOnsMenu.Submenus
for ($j = 0; $j -lt $args.count; $j++)
{
$name = $args[$j]
$count = $submenu.count
#Write-host "arg0: $name $count"
for ($i = 0; $i -lt $submenu.count; $i++)
{
$found = $false
if ($Submenu[$i].DisplayName -eq $name)
{
#Write-host "found toplevel menu $name"
$found = $True
if ( $j -eq ($args.count - 1))
{
Write-host 'Removing'
$null = $submenu.remove($Submenu[$i])
}
else
{
$submenu = $Submenu[$i].submenus
}
break
}
}
if (! $found)
{
Write-host "Menuitem not found"
break
}
}
}
Remove-IseMenuItem Edit Pad
# Remove-Child $Submenu[$i] $Name | out-null
But this looks like an old PowerShell V1 coding style. It doesn't check that all arguments are strings. Please can someone show me, how to set up a PowerShell V2 advanced function parameter declaration for this.
