The previous section focuses on the common aliases in PowerShell and how to view real PowerShell commands by aliases, the naming conventions for PowerShell aliases, and how to create your own aliases (PowerShell built-in aliases cannot be changed) As well as the compatibility aliases in PowerShell, click here for more information.
This section mainly contains the following content.
PowerShell command Auto-complete function.
Use the cmd command in PowerShell.
Summarize
Command Auto-complete function in PowerShell
PowerShell command Auto-completion is also known as tab extension, auto-completion of the function can greatly improve the speed and accuracy of command input, in PowerShell through the TAB key to use the function of auto-completion.
Auto-complete function of file name or path
If you want to enter a file name in a certain path, you can enter some content and press the TAB key to complete it.
PS c:\> CD D:\MyPowerShellPS d:\mypowershell> m<tab>
When you press the TAB key, PowerShell automatically expands the name to the first match it finds. Press the TAB key repeatedly to display all available options individually. The result of the above command executes as follows
PS c:\> cd D:\MyPowerShellPS d:\mypowershell>. \mandatory.ps1
If you want to display previous options, you can press the Shift+tab key to toggle the previous options.
The tab extension for cmdlet commands is slightly different. If you want to use the Tab extension for the cmdlet name, enter the first part (verb) of the command name and the hyphen that follows it. You can fill in more parts of the name for a more accurate match. For example, if you enter Get-co and then press the Tab key, PowerShell automatically expands it to the Get-command cmdlet (its letter case will also change to the standard form, although the PowerShell command does not differentiate between the case of the command). Continue pressing the TAB key, PowerShell will replace the previous name with the only other matching cmdlet name Get-content, and press Shift+tab to switch to the previous command , which is get-command.
tab extensions and Shift+tab extensions can be reused on the same line . For example, you can use the Tab extension for the name of the Get-content cmdlet by entering the following command:
Ps> get-con<tab>
When you press the TAB key, the command expands to:
Ps> get-content
When you continue to press the TAB key, the command expands to:
Ps> Get-commond
You can also switch to the previous command by pressing the Shift+tab key.
Ps> get-content
Note: The tab extension is limited by the fact that tab is always interpreted as trying to complete a word. If a command cannot be matched to any of the appropriate commands, PowerShell does not appear as expected.
Using the cmd command in PowerShell
All Windows commands can be executed in PowerShell, and Windows programs with a graphical user interface (such as Notepad, calculator, paint, etc.) can be started at the PowerShell command prompt. You can also capture the text generated by Windows programs (the results of the Windows command execution) and use the text content further in PowerShell.
For example, use the ipconfig command in PowerShell.
PS d:\mypowershell> ipconfigwindows IP configurationethernet Adapter Local Area Connection: Connection-specific DNS Suffix. : IP address ...: 192.168.1.124 Subnet Mask ........... ..... : 255.255.255.0 Default Gateway ..... . : 192.168.25.1
You can also use PowerShell cmdlets, such as select-string, to manipulate the text returned by Windows programs.
PS d:\mypowershell> ipconfig | Select-string-pattern 255 Subnet Mask ........... : 255.255.255.0
The above command uses the pipe operator (|) Sending the results of the IPConfig command to PowerShell's select-string cmdlet,select-string searches the text in the string that the window command executes the results of. The above command is to find content that contains 255.
When Windows commands or tools have parameters, such as the "-R" (restart) parameters of Shutdown, PowerShell passes parameters to the tool without interpreting them.
Note that if the tool uses PowerShell reserved words or uses a command format unfamiliar to PowerShell, such as the "-d:debug=false" parameter of Nant (PowerShell interprets this parameter as two parameters: "-D" and "debug= False "), enclose the parameter in quotation marks to indicate that PowerShell should send the parameter to the tool without explanation.
Summarize
By studying this section, you should be familiar with the following content.
Use PowerShell commands to automatically complete the function.
Understand that all Windows commands can be executed in PowerShell.
This article from "Flower Blossom Fall" blog, declined reprint!
Command Auto-complete function in PowerShell and use Windows commands