Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 1519

Intellisense in Windows PowerShell ISE 3.0

$
0
0

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)

image

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:

image

 

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

image

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?” :-)

image

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.

image

 

Paths

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

image

 

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:\

image

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

imageNote 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:

image

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:

image

History

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

image

Types & Namespaces

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

image

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:

image

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

image

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:
    • image: Command
    • image: Container
    • image: File / item
    • image: Method
    • image: Property
    • image: Parameter
    • image: Parameter value
    • image: Variable
    • image: History
    • image: 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. :-)

image

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 :-)

image

 

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


Viewing all articles
Browse latest Browse all 1519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>