Intellisense in Windows PowerShell ISE 3.0

PowerShell Team

This blog post applies to the Windows PowerShell Integrated Scripting Environment (ISE) in Windows 8 and Windows Server 2012.  The ISE is also fully supported and available when Server 2012 is deployed using the Minimal Server Interface.  To start ISE, type ise  in a PowerShell console and press Enter

Very few things can be considered “cool” in an interactive command-line environment. Intellisense sure counts as one of the few exceptions.  While tab completion has always been a cornerstone of PowerShell usability (and continues to be), my struggle with tab completion is that after cycling through the 5th option, I would have already forgotten the first 3 :-).  Discoverability is not optimal either, because a user doesn’t always know when tab completion would work, so it becomes a bit of a trial-and-error exercise.  Intellisense provides the following added benefits over tab completion:

  • Automatic drop-down when options are available – better discoverability
  • A view of a dozen (or so) options at a glance – no need to remember the options
  • Icons to help identify the type of options available
  • Syntax tooltips

 

Commands, Parameters, and Values

Type Set- and a list of cmdlets is dropped down (as well as scripts if you have any in the current path).  If you click (or navigate via keyboard) to Set-ExecutionPolicy for example, a tooltip displays the syntax of the cmdlet.  Of course, if you start typing Ex, the list in the drop-down is narrowed down to the matching set only. (More on matching later)

set execution policy

You can press Enter or Tab to accept the value and once you press Space and type , another drop-down appears, this time with the parameter options:

dropdown detail

 

Go ahead and select –ExecutionPolicy, and once you press Space, the allowed values appear (this works for enumerations and ValidateSet):

dropdown detail 2

By the way … the Intellisense icon colors for parameters and parameter values match ISE’s default color scheme for parameters and parameter values.  Of course, if you’re typing in the console, parameters and parameter values have totally different colors to match the blue background, and you might be going: “Huh? what’s with the weird colors?” 🙂

what's up with all the weird colors?

Smart Matching

When you type Get-, Intellisense kicks in.  If you continue to type Get-Switch, Intellisense displays all the options which match Get-*Switch*.  This comes in really handy when you’re looking for a cmdlet, and don’t remember its exact name or prefix.

intellisense helps with selection

 

Paths

Type dir c:\ and Intellisense displays a list of files and folders (items) in the path you specified.

dir c:\

 

Here, too, we try to do smart matching: If you use Set-Location, we only display containers (folders), not files (items), since it wouldn’t make sense.  Here’s cd c:\

cd c:\

Path completion works for any PowerShell provider, not just the file system. Try: dir hklm:\

dir hklm:\

Note that using tab completion and/or Intellisense with environment variables may produce undesired results, for example when you’re trying to specify the Windows folder using the SystemDrive environment variable:

environment variable

When you press Enter or Tab, the entire string becomes: “C:\Windows”, which is machine-specific, and may not be what you want.

Variables

As soon as you type $, Intellisense kicks in, showing user-defined and pre-defined variables:

intellisense showing predefined and user-defined variables

History

Type # followed by Ctrl+Space to show your command history at a glance:

 

history

Types & Namespaces

Another cool feature is namespace completion.  Try [Initials and press Ctrl+Space

initials

Press Enter and you should see the namespace & type expanded to: [System.Management.Automation.Runspaces.InitialSessionState.  Yes, this means that you no longer have to know which namespace a type lives in, before you can use it. 🙂

Properties & Methods

Try [int]:: and notice how Intellisense kicks in and displays the static members of the integer class: integer class

Try (“PowerShell rocks!”). (notice the period at the end), and observe how Intellisense kicks in and displays the members of the string object:

members of the string object

Helpful Tips

  • If you accidentally dismiss the Intellisense drop-down, use Ctrl+Space to invoke Intellisense again.
  • Use the Options dialog if you want to turn Intellisense ON/OFF for each pane, or if you want to change the default behavior of the Enter key for selection.
  • Here is the list of icons and what they mean:
    • command: Command
    • container: Container
    • file: File / item
    • method: Method
    • property: Property
    • parameter: Parameter
    • parameter value: Parameter value
    • variable: Variable
    • history:History
    • type: Type

 

More Cool Intellisense

Start a new script and type: $x = Get-Process m*.  Without even running this, as soon as you type $x., you see Intellisense for the members of a process object. 🙂

process object

You can experience this at the command line as well: Try Get-Service a* | where {$_. and notice how Intellisense kicks in, and displays all members of a service object.  No more Get-Member before you run a where filter 🙂

where filter

 

This is just the tip of the iceberg, so look out for an upcoming blog from Jason Shirk on more cool Intellisense features.

 

 

ref@

Refaat Issa

Program Manager, Windows Server Manageability

Microsoft Corporation

1 comment

Discussion is closed. Login to edit/delete existing comments.

  • Jonny Hotchkiss 0

    This is great, thanks!
    didn’t know the # history trick, also thought the ‘automatic-variable’ intellisense didn’t exist, but seems it just depends…

    I was trying to pipe each get-command (name) as a variable to the get-help command that Selects any parameters where PipelineInput is like ‘true’
    (PS doesn’t like the 2nd wildcard?)

    Eg Instead of using a command like Get-Member
    #no tab completion on select fields / $_.
    Get-Help Get-Member -Parameter * | Where {$_.PipelineInput -eq ‘true*’} | select Name, PipelineInput

    #result from above command
    name pipelineInput
    —- ————-
    InputObject True (ByValue)

    #When trying to use the intellisense to complete this statement, it doesn’t work –
    Get-Help Get-Command -Parameter * | Where {$_.

    ^is PS confused by the many commands in the statement (and is there a syntactic solution to this?!)

    The command I’m building is currently syntactically incorrect – need to work on foreach/select/reference logic – I can get it to list the parameters that can be pipelined, but struggling to reference the $parameter in output, eg
    #works, no command ref

    Get-Command * -CommandType Cmdlet | %{ $cName = $_.Name; Get-Help $cName -Parameter * -ErrorAction SilentlyContinue | where {$_.pipelineInput -like ‘true*’} | Select Name, PipelineInput }

    Tried a few things to pipe, but need to master out-host et al!

Feedback usabilla icon