Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

PowerShell ISE Case Closed

Posted on April 5, 2011

When writing a PowerShell script or function, things like indentations, white space and case make a big difference in how easy it is to read and understand your code. Sometimes it can be helpful to have a word or sentence in all upper case so that it stands out. Here is a simple set of commands you can insert into your PowerShell ISE profile to convert selected text to all upper or lower case.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

The concept is incredibly easy. I trust you know that a string object has method called ToUpper().

[cc lang="Powershell"]
PS C:\> $s="abcdefg"
PS C:\> $s.toUpper()
ABCDEFG
[/cc]

The method doesn't change the value of $s, merely returns an uppercase version. There is also a corresponding ToLower() method. In the ISE, we can use the object model to reference any selected text using

[cc lang="Powershell"]
$psise.CurrentFile.Editor.SelectedText
[/cc]

This will be a string object which means we can call the ToUpper() and toLower() methods.

[cc lang="PowerShell"]
$psise.CurrentFile.Editor.SelectedText.toUpper()
[/cc]

But what do we do with the result? We can insert it back into the file using the ISE object model.

[cc lang="PowerShell"]
$psise.currentfile.editor.insertText($psise.CurrentFile.Editor.SelectedText.toUpper())
[/cc]

Knowing this, I added two lines to my ISE profile script to append a couple of items to the AddOns menu.

[cc lang="PowerShell"]
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Convert to uppercase",
{$psise.currentfile.editor.insertText($psise.CurrentFile.Editor.SelectedText.toUpper())},"CTRL+ALT+U") | Out-Null
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Convert to lowercase",
{$psise.currentfile.editor.insertText($psise.CurrentFile.Editor.SelectedText.toLower())},"CTRL+ALT+L") | Out-Null
[/cc]

In the ISE you can run psedit $profile to edit. On my menu I now have two additional options, "Convert to uppercase" and "Convert to lowercase" with the corresponding keyboard shortcuts. If you don't want any shortcuts use $Null.

You can download these commands in text file here.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

6 thoughts on “PowerShell ISE Case Closed”

  1. Don Jones says:
    April 5, 2011 at 10:20 pm

    Neat… but wow me: Can you make it so that it converts aliases to full cmdlet names? Should be possible using Get-Alias, right?

    You should do a whole session on customizing and tweaking the ISE. Seriously.

    1. Jeffery Hicks says:
      April 6, 2011 at 7:34 am

      Hmmm…I thought the ISE Pack had such a tool but apparently not. I’ll put it on the to do list. Thanks for the suggestions.

  2. Vincent says:
    April 6, 2011 at 2:51 am

    Thank You ! Just what I needed 🙂

    I think I’ve read all your post on menu add-ons for ISE. Would you care to share an exact list of what you’ve got in your add-on menu however, just in case I missed something ? 🙂

    I’m fairly new to powershell and I just love how easy it is to customise & personalise ISE.

    1. Jeffery Hicks says:
      April 6, 2011 at 7:39 am

      When I can find the time my plan is to package what I have so far as a module. But for now search my blog for ‘ISE’. You should find things like ISE Most Recent files, insert date time, open script folder, new comment help and new function. But perhaps I’d better package everything sooner rather than later.

  3. Alexey Martseniuk says:
    April 9, 2011 at 3:56 pm

    Hidden ISE shortcuts:

    Ctrl + Shift + U – convert to uppercase
    Ctrl + U – convert to lowercase

    1. Jeffery Hicks says:
      April 10, 2011 at 9:27 am

      Well isn’t that handy! I thought there were shortcuts but I couldn’t find anything on the menu. Always nice to learn something new.

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d