ISEMenuItem 对象是 Microsoft.PowerShell.Host.ISE.ISEMenuItem 类的一个实例。“加载项”菜单上的所有菜单对象都是 Microsoft.PowerShell.Host.ISE.ISEMenuItem 类的成员。
属性
DisplayName
只读属性,用于获取菜单的名称。
# Get the display name of the Add-ons menu item $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Clear() $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add("_Process",{get-process},"Alt+P") $psISE.CurrentPowerShellTab.AddOnsMenu.DisplayName
Action
只读属性,用于获取要在单击菜单项时调用的脚本(块)。
# Get the action associated with the first submenu item. $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Clear() $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add("_Process",{get-process},"Alt+P") $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus[0].Action # Invoke the script associated with the first submenu item (Note the “.” At the beginning of the command). # Invoke the action $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus[0].Action.Invoke()
Shortcut
只读属性,用于获取菜单项的 Windows 输入键笔势。
# Get the shortcut for the first submenu item. $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Clear() $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add("_Process",{get-process},"Alt+P") $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus[0].Shortcut
Submenus
只读属性,用于获取菜单项的子菜单列表。
# List the submenus of the Add-ons menu $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Clear() $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add("_Process",{get-process},"Alt+P") $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus
脚本示例
为了更好地了解“加载项”菜单及其可编写脚本的属性的用法,请通读以下脚本示例:
# This is a scripting example that shows the use of the Add-ons menu. # Clear the Add-ons menu if one exists $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Clear() # Add an Add-ons menu with an accessor. # Note the use of “_” as opposed to the “&” for mapping to the fast key letter for the menu item. $menuAdded = $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add("_Process",{get-process},"Alt+P") # Add a nested menu. $parentAdded = $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add("Parent",$null,$null) $parentAdded.SubMenus.Add("_Dir",{dir},"Ctrl+Shift+D")
另请参阅