PowerShell ii

I try and work as much as possible from the PowerShell host, as opposed to using the mouse to point and click. One common use case is for me to open different file types.

As with everything in PowerShell, there are several ways to do this.

I could enter the file path as a parameter to the program that opens the file type. A relatively easy example would be to open a text file in Windows Notepad. If I have a file called “hello.txt” in my PWD (Present Working Directory) I could type notepad '.\hello.txt'.

This would launch that file in Notepad.

But what if I want to open an Excel file. By default, I CANNOT type excel ‘.\hello.xls’.

Alas, there is an easy way to open this file. Just type ii '.\hello.xls'

By the way, I don’t type out the whole file name or even the single quotes around the file name. I just type the first couple letters of the file name and press tab…. PowerShell tabs through all matching files for me. So I would just type ii hel<tab><enter>.

ii is an alias for Invoke-Item. It does not require knowing the name or location of the program that opens any given file type.

Advanced Aside: ii opens the file based on the Windows file extension mappings. When you install most programs on your machine, they register with Windows to open specific file extensions by default. It usually is not necessary, but you can change these mappings in the Control Panel.

One thought on “PowerShell ii

  1. Isaac Brown

    I usually find myself changing file extension default mappings when working with files such as .html/.html/.js . These are mapped by default to a browser or javascript code blocker. Also, Command Prompt can also tab through files, which is really great. Thanks, great article.


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