Find a Command to Accomplish a Task
1. Problem
You want to accomplish a task in PowerShell but don’t know the command or cmdlet to accomplish that task.
2. Solution
Use the Get-Command cmdlet to search for and investigate commands.
To get the summary information about a specific command, specify the command name as an argument:
       Get-Command CommandName
To get the detailed information about a specific command, pipe the output of Get-Command to the Format-List cmdlet:
       Get-Command CommandName | Format-List
To search for all commands with a name that contains text, surround the text with asterisk characters:
       Get-Command *text*
To search for all commands that use the Get verb, supply Get to the -Verb parameter:
       Get-Command -Verb Get
To search for all commands that act on a service, supply Service to the -Noun parameter:
       Get-Command -Noun Service
3. Discussion
One of the benefits that PowerShell provides administrators is the consistency of its command names. All PowerShell commands (called cmdlets) follow a regular Verb-Noun pattern. For example: Get-Process, Get-EventLog, and Set-Location. The verbs come from a relatively small set of standard verbs (as listed in Appendix D, Standard PowerShell Verbs), and describe what action the cmdlet takes. The nouns are specific to the cmdlet and describe what the cmdlet acts on.
Knowing this philosophy, you can easily learn to work with groups of cmdlets. If you want to start a service on the local machine, the standard verb for that is Start.A good guess would be to first try Start-Service (which in this case would be correct), but typing Get-Command -Verb Start would also be an effective way to see what things you can start. Going the other way, you can see what actions are supported on services by typing Get-Command -Noun Service.
See Section 1.5, “Get Help on a Command” for a way to list all commands along with a brief description of what they do.
The Get-Command cmdlet is one of the three commands you will use most commonly as you explore Windows PowerShell. The other two commands are Get-Help and Get-Member.
There is one important point when it comes to looking for a PowerShell command to accomplish a task. Many times, that PowerShell command does not exist, because the task is best accomplished the same way it always was—shutdown.exe to reboot a machine, netstat.exe to list protocol statistics and current TCP/IP network connections, and many more.
For more information about the Get-Command cmdlet, type Get-Help Get-Command.
4. See Also
· Section 1.5, “Get Help on a Command”
Tags: cmd, command, find, kernel, power shell, shell, task, task manager
