Use Powershell to retrieve commands you don’t understand
Try to use Powershell to complete the Powershell command line
When working with Powershell, sometimes you forget a cmdlet or want to know which cmdlets are available. In this case it’s better to look it up on the internet, but you can also do it using a Powershell function.
The following methods are useful for investigating Powershell using Powershell.
- Input completion
- Search cmdlets
- Ask for help
Input completion
Saying “search” might be a bit of an understatement, but Powershell has a feature that does cmdlets that do part of what you type. It has the same functionality as the Linux shell.
- Enter part of the cmdlet and press Tab
- Half-enter the cmdlet and press Ctrl + Spacebar
This feature allows you to type cmdlets faster without having to remember the exact spelling. Completion can be used to enter commands and options, select file paths, and select constants.
If you type part of a cmdlet and then press the Tab key, the part of the command you type will be completed. If you press Tab again, more suggestions will appear. If you want to return to the displayed candidates, press Shift + Tab.
PS C:\Users\Main> Get-help Get-Chil #Enter part of the force and press the Tab key PS C:\Users\Main> Get-help Get-ChildItem #The command will be automatically completed
When completing with Ctrl+Space, all possible completions will be displayed and you can use the arrow keys to select one. When an option is completed, information such as the option’s format and possible values are displayed at the bottom.
PS > Get-Net #Enter into Get-Net and press Ctrl + Space PS > Get-Net6to4Configuration #Be able to select the displayed command line list Get-Net6to4Configuration Get-NetIPAddress Get-NetAdapter Get-NetIPConfiguration ? PS > Get-ChildItem - # Enter here, then Ctrl + Space PS > Get-ChildItem -Path # Can display and select candidate options. Path Depth File ErrorAction OutVariable LiteralPath Force Hidden WarningAction [string[]] Path # Furthermore, optionally specified values and other information are displayed at the bottom.
Search cmdlets
You can use Get-Command to search for cmdlets. The cmdlet name is displayed if you enter it in the Get-Command parameter.
PS> get-command Get-ChildItem CommandType Name Version Source ----------- ---- ------- ------ Cmdlet Get-ChildItem 3.1.0.0 Microsoft.PowerShell.Management
Just looking at this output, I don’t know what the useful cmdlet is. (wildcard) can be specified in the Get-Command parameter. You can search for cmdlets by specifying .
PS > get-command Get-C*dItem CommandType Name Version Source ----------- ---- ------- ------ Cmdlet Get-ChildItem 3.1.0.0 Microsoft.PowerShell.Management
Powershell cmdlets have a – structure. Using Get-Command, you can search by specifying the noun part by specifying -Noun or by specifying the verb part by specifying -Verb. In published module cmdlets, a string is often added to the beginning of the noun part to help identify the module. It’s designed so that you can even search for cmdlets by name.
# When searching for a name PS > Get-Command -Noun Item CommandType Name Version Source ----------- ---- ------- ------ Cmdlet Clear-Item 3.1.0.0 Microsoft.PowerShell.Management Cmdlet Copy-Item 3.1.0.0 Microsoft.PowerShell.Management Cmdlet Get-Item 3.1.0.0 Microsoft.PowerShell.Management Cmdlet Invoke-Item 3.1.0.0 Microsoft.PowerShell.Management Cmdlet Move-Item 3.1.0.0 Microsoft.PowerShell.Management Cmdlet New-Item 3.1.0.0 Microsoft.PowerShell.Management Cmdlet Remove-Item 3.1.0.0 Microsoft.PowerShell.Management Cmdlet Rename-Item 3.1.0.0 Microsoft.PowerShell.Management Cmdlet Set-Item 3.1.0.0 Microsoft.PowerShell.Management # Also lock the verb part PS > Get-Command -Noun Item -Verb Get CommandType Name Version Source ----------- ---- ------- ------ Cmdlet Get-Item 3.1.0.0 Microsoft.PowerShell.Management </code><img class="look-more-preCode contentImg-no-view" src="//i2.wp.com/csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreBlack.png" alt ="" title="">
By specifying a module with -Module, you can inspect the cmdlets provided by that module. This allows you to know what commands are provided even for modules with little online information.
# After installing the Selenium module, find the command line that can be used. > Get-Command -Module Selenium CommandType Name Version Source ----------- ---- ------- ------ AliasEnter-SeUrl 3.0.1 Selenium Alias Find-SeElement 3.0.1 Selenium Alias Start-SeLegacyEdge 3.0.1 Selenium Function Clear-SeAlert 3.0.1 Selenium Function Get-SeCookie 3.0.1 Selenium .......
Find cmdlet information
Information about cmdlets can be found using Get-Help. Alternatively, you can check the cmdlet information by adding the -? parameter to the cmdlet. However, it is in English.
By using the cmdlet parameters -Detailed and -Full, you can specify the amount and content of information to be displayed.
PS C:\Users\Main> Get-help Get-ChildItem -Parameter * #Display information about all parameters -Attributes <System.Management.Automation.FlagsExpression`1[System.IO.FileAttributes]> {<!-- -->{<!-- -->Fill Attributes Description}} must be false location named Defined value None Allow input pipeline False Allow wildcard characters false -Depth <UInt32> {<!-- -->{<!-- -->Fill Depth Description}} ? ? ? </code><img class="look-more-preCode contentImg-no-view" src="//i2.wp.com/csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreBlack.png" alt ="" title="">
If you speak English, this will be a very useful feature. If your primary language is Japanese, it’s honestly faster to look it up on the internet. If you refer to the usage examples, you can roughly understand how to use them just by looking at them.
If you don’t want to search online, you can use Get-Help with the -online parameter to display online help from your browser.
When you write cmdlets using Function, you can also embed annotation-based help.