Changes

Jump to: navigation, search

The Basics of the Windows PowerShell 1.0 Interactive Shell

2,200 bytes added, 16:13, 13 November 2008
PowerShell Command Completion
== PowerShell Command Completion ==
 
After a few characters of a command, parameter, file name, variable or variable property have been entered at the PowerShell command line prompt, the Tab key may be pressed to instruct PowerShell to complete the remainder of the entry. For example, if the first few characters of a command have been entered, PowerShell will try to find the best match for a command and fill in the remainder of the command name. If the command selected by PowerShell is not the correct one, pressing the Tab key repeatedly will cycle through all the possible matches until the correct one is displayed. Similarly, if a partial file name is entered followed by the Tab key, PowerShell will populate the command line with file name from the current directory. If, once again, the first match displayed by PowerShell is not the desired file, the Tab key can be pressed repeatedly until the correct match is displayed.
 
Tab completion is particularly useful for finding the properties and methods of a variable. As an example, suppose a variable named ''$mynumber'' is assigned a numerical value and we want to find out what the type of that value is. We assume there must be a method we can call on on the varaible to get the type but do not know what that method is called. To cycle through the available methods we simply enter the name of the variable, followed by a ''.'' character and then the first few characters of the method (we are assuming it will begin with ''Get''), We then press the ''Tab'' key until we find the method that does what we need, in this case, ''GetType()'':
 
<pre>
PS C:\Users\Administrator> $mynum=231.321123
PS C:\Users\Administrator> $mynum.Get <Tab>
</pre>
 
The first match displayed by PowerShell will likely be ''GetHashCode(''. Pressing ''Tab'' a second time displays ''GetType('' which is almost certainly the one we want. We then enter the closing parentheses '')'' and press enter to execute the command.
 
<pre>
PS C:\Users\Administrator> $mynum.GetType()
 
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Double System.ValueType
</pre>
== Customizing the PowerShell Window ==

Navigation menu