Using the Get-Command Cmdlet

Listing All the Windows PowerShell Cmdlets

Can’t remember the name of each and every Windows PowerShell cmdlet? Don’t worry about it; that’s one of the things Get-Command can help you with. Just type Get-Command without any additional parameters and you’ll get back a list of all the Windows PowerShell cmdlets:

Get-Command

That list will look something like this:

CommandType     Name                            Definition
-----------     ----                            ----------
Cmdlet          Add-Content                     Add-Content [-Path] <String[...
Cmdlet          Add-History                     Add-History [[-InputObject] ...
Cmdlet          Add-Member                      Add-Member [-MemberType] <PS...
Cmdlet          Add-PSSnapin                    Add-PSSnapin [-Name] <String...
Cmdlet          Clear-Content                   Clear-Content [-Path] <Strin...

Good point: that is a little hard to read, isn’t it? Try piping the results of Get-Command through the Format-List cmdlet (we’ve included the asterisk to indicate that we want back all the properties for each cmdlet):

Get-Command | Format-List *

That returns information similar to this for each cmdlet:

Name             : Write-Verbose
CommandType      : Cmdlet

DLL              : C:\WINDOWS\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.U
                   tility\1.0.9567.1__31bf3856ad364e35\Microsoft.PowerShell.Com
                   mands.Utility.dll
Verb             : Write
Noun             : Warning
HelpFile         : Microsoft.PowerShell.Commands.Utility.dll-Help.xml
PSSnapIn         : Microsoft.PowerShell.Utility
ImplementingType : Microsoft.PowerShell.Commands.WriteWarningCommand
ParameterSets    : {__AllParameterSets}
Definition       : Write-Warning [-Message] <String> [-Verbose] [-Debug] [-Erro
                   rAction <ActionPreference>] [-ErrorVariable <String>] [-OutV
                   ariable <String>] [-OutBuffer <Int32>]

Name             : Write-Warning
CommandType      : Cmdlet

Oh: all you really wanted was the cmdlet name? That’s easy enough; just use Select-Object to filter out all the properties except Name:

Get-Command | Select-Object name

Is this more of what you had in mind?

Name
----
Add-Content
Add-History
Add-Member
Add-PSSnapin
Clear-Content
Clear-Item
Clear-ItemProperty
Clear-Variable

Here’s a nifty way to use Get-Command. This command grabs the set of cmdlets installed on a computer and pipes that information to Get-Help. Get-Help dutifully retrieves the help topic for each cmdlet, then uses the Out-File cmdlet to save all those help topics to a file named C:\Scripts\Help.txt:

Get-Command | Get-Help | Out-File c:\scripts\help.txt

Run that command and, within a minute or so, you’ll have built yourself a document containing the on-line help available for each and every cmdlet.

Get-Command Aliases
  • gcm