PowerShell

How to add a custom menu item in PowerShell ISE

When I read the excellent book “Office 365” by Markus Widl, I was surprised that the author covered so many PowerShell topics. Great book! Especially one topic in his book is interesting. Adding menu items in PowerShell ISE to connect to your Office 365 tenant. Shame on me, I didn’t know this could be done. Anyway, now I will show you how to add menu items in PowerShell ISE. I will make a menu that makes a remote connection to a server, so change the example of the book a little bit. Let’s dive in.

PowerShell ISE Add-ons

So what we want to achieve is to add a menu item here:

Unbenannt

For example, we want to add a menu item that connects to one of my domain controller. That will then look like this:

Unbenannt.PNG

Ok, let’s make this happen.

Creating an Add-on Menu in PowerShell ISE

Open PowerShell ISE. Build on the following example.


$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add(
"Connect to DC02",
{
$cred = Get-Credential
Enter-PSSession -ComputerName DC02 -Credential $cred
},
"CTRL+ALT+2")

Note that the newly created add-on will disappear when you close PowerShell ISE. To implement your add-on permanently you have to put your code into your PowerShell ISE profile.

Putting the Add-on into the PowerShell ISE Profile

First, create a PowerShell ISE profile for the current user. Open a new tab in PowerShell ISE and type the following line:


New-Item -Path $PROFILE.CurrentUserCurrentHost -Force

Now open the profile file.


notepad $PROFILE.CurrentUserCurrentHost

Unbenannt

Finally, copy the recently created code into the profile file. Click Save.

Close and reopen PowerShell. Have fun with your new add-on which is now implemented permanently for your user account.

See also

PowerShell: Customizing the Title Bar of your PowerShell Console Window

PowerShell for Beginners (Part 6): PowerShell Profiles and the ISE

Categories: PowerShell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.