Tag Archives: Tips

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.