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")
請參閱