PowerShell Core for Linux Administrators Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it…

Get-Command can help determine the best cmdlet for a task. To find cmdlets, follow these steps:

  1. Enter Get-Command to get a list of all of the available cmdlets in PowerShell. The number of cmdlets returned will change based on when you last updated PowerShell and the modules you have loaded:
PS> Get-Command

This may not be particularly useful—what would you do with a list of commands if you were looking for something to do with processes?

  1. The lazy way of doing this is by using the following command:
PS> Get-Command *proc*
  1. To be specific and look for a command that deals with processes, use the following code:
PS> get-command -no process
PS> # Verbose version: Get-Command -Noun 'Process'
In PowerShell, the convention is to always have the noun in the singular form. Therefore, it is always Process, Service, Computer, and so on, and never Processes, Services, Computers, and so on.
  1. To look for cmdlets that help you export objects, use the following code:
PS> get-command -v export
PS> # Verbose version: Get-Command -Verb 'Export'
PowerShell has a standard set of verbs. This is to ensure the discoverability of cmdlets. If you use a nonstandard verb when creating your cmdlets, PowerShell will warn you that your cmdlet may not be discoverable. To get a list of approved verbs, run the Get-Verb cmdlet.
  1. The -Noun and -Verb parameters also accept wildcards:
PS> get-command -no proc*
  1. Imagine that you just installed a PowerShell module (more on that later) and would like to look for cmdlets packaged in the module. For this example, we will use the SqlServer module:
PS> get-command -v get -m sqlserver 
PS> # Verbose version: Get-Command -Verb 'Get' -Module 'SqlServer'