0% found this document useful (0 votes)
4 views5 pages

Using Cmdlets To Explore PowerShell

The document provides an overview of PowerShell cmdlets, which are commands used within PowerShell, following a Verb-Noun naming convention for clarity. It explains how to discover and filter commands using specific cmdlets like Get-Command, Get-Verb, and Get-Member, as well as how to explore command outputs and properties. Additionally, it highlights the importance of understanding verbs and nouns in cmdlet names to effectively utilize PowerShell commands.

Uploaded by

ptykxhrytq
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Using Cmdlets To Explore PowerShell

The document provides an overview of PowerShell cmdlets, which are commands used within PowerShell, following a Verb-Noun naming convention for clarity. It explains how to discover and filter commands using specific cmdlets like Get-Command, Get-Verb, and Get-Member, as well as how to explore command outputs and properties. Additionally, it highlights the importance of understanding verbs and nouns in cmdlet names to effectively utilize PowerShell commands.

Uploaded by

ptykxhrytq
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

10/30/23, 2:41 PM Discover PowerShell - PowerShell | Microsoft Learn

PowerShell cmdlets
PowerShell comes with hundreds of preinstalled commands. PowerShell commands are called cmdlets
(pronounced command-lets).

The name of each cmdlet consists of a Verb-Noun pair. For example, Get-Process . This naming convention makes
it easier to understand what the cmdlet does. It also makes it easier to find the command you're looking for. When
looking for a cmdlet to use, you can filter on the verb or noun.

Using cmdlets to explore PowerShell


When you first pick up PowerShell, it might feel intimidating as there seems to be so much to learn. PowerShell is
designed to help you learn a little at a time, as you need it.

PowerShell includes cmdlets that help you discover PowerShell. Using these three cmdlets, you can discover what
commands are available, what they do, and what types they operate on.

Get-Verb . Running this command returns a list of verbs that most commands adhere to. The response
includes a description of what these verbs do. Since most commands follow this naming convention, it sets
expectations on what a command does. This helps you select the appropriate command and what to name a
command, should you be creating one.
Get-Command . This command retrieves a list of all commands installed on your machine.
Get-Member . It operates on object based output and is able to discover what object, properties and methods
are available for a command.
Get-Help . Invoking this command with the name of a command as an argument displays a help page
describing various parts of a command.

Using these commands, you can discover almost anything you need to know about PowerShell.

Verb
Verb is an important concept in PowerShell. It's a naming standard that most cmdlets follow. It's also a naming
standard you're expected to follow when you write your own commands. The idea is that the Verb says what you're
trying to do, like read or maybe change data. PowerShell has a standardized list of verbs. To get a full list of all
possible verbs, use the Get-Verb cmdlet:

PowerShell

Get-Verb

The cmdlet returns a long list of verbs. The Description provides context for what the verb is meant to do. Here's
the first few rows of output:

Output

Verb AliasPrefix Group Description


---- ----------- ----- -----------
Add a Common Adds a resource to a container, or attaches an item
to another item
[Link] 1/5
10/30/23, 2:41 PM Discover PowerShell - PowerShell | Microsoft Learn

Clear cl Common Removes all the resources from a container but does
not delete the container
Close cs Common Changes the state of a resource to make it
inaccessible, unavailable, or unusab…
Copy cp Common Copies a resource to another name or to another
container
Enter et Common Specifies an action that allows the user to move into
a resource
Exit ex Common Sets the current environment or context to the most
recently used context
...

Find commands with Get-Command


The Get-Command cmdlet returns a list of all available commands installed on your system. The list you get back is
quite large. You can limit the amount of information that comes back by filtering the response using parameters or
helper cmdlets.

Filter on name
You can filter the output of Get-Command using different parameters. Filtering allows you to find commands that
have certain properties. The Name parameter allows you to find a specific command by name.

PowerShell

Get-Command -Name Get-Process

Output

CommandType Name Version Source


----------- ---- ------- ------
Cmdlet Get-Process [Link] [Link]

What if you want to find all the commands that work with processes? You can use a wildcard * to match other
forms of the string. For example:

PowerShell

Get-Command -Name *-Process

Output

CommandType Name Version Source


----------- ---- ------- ------
Cmdlet Debug-Process [Link] [Link]
Cmdlet Get-Process [Link] [Link]

[Link] 2/5
10/30/23, 2:41 PM Discover PowerShell - PowerShell | Microsoft Learn

Cmdlet Start-Process [Link] [Link]


Cmdlet Stop-Process [Link] [Link]
Cmdlet Wait-Process [Link] [Link]

Filtering on Noun and Verb


There are other parameters that filter on verb and noun values. The verb part of a command's name is the leftmost
part. The verb should be one of the values returned by the Get-Verb cmdlet. The rightmost part of a command is
the noun part. A noun can be anything.

Filter on verb. In the command Get-Process , the verb part is Get . To filter on the verb part, use
the Verb parameter.

PowerShell

Get-Command -Verb 'Get'

This example lists all commands that use the verb Get .

Filter on noun. In the command Get-Process , the noun part is Process . To filter on the noun, use
the Noun parameter. The following example returns all cmdlets the have nouns starting with the letter U .

PowerShell

Get-Command -Noun U*

Also, you can combine parameters to narrow down your search, for example:

PowerShell

Get-Command -Verb Get -Noun U*

Output

CommandType Name Version Source


----------- ---- ------- ------
Cmdlet Get-UICulture [Link] [Link]
Cmdlet Get-Unique [Link] [Link]
Cmdlet Get-Uptime [Link] [Link]

Use helper cmdlets to filter results


You can also use other cmdlets to filter results.

Select-Object . This versatile command helps you pick out specific properties from one or more objects.
You can also limit the number of items you get back. The following example returns
the Name and Source property values for the first 5 commands available in the current session.
[Link] 3/5
10/30/23, 2:41 PM Discover PowerShell - PowerShell | Microsoft Learn

PowerShell

Get-Command | Select-Object -First 5 -Property Name, Source

Output

Name Source
---- ------
Add-AppPackage Appx
Add-AppPackageVolume Appx
Add-AppProvisionedPackage Dism
Add-AssertionOperator Pester
Add-ProvisionedAppPackage Dism

For more information, see Select-Object.

Where-Object . This cmdlet lets you filter the objects returned based on the values of properties. The
command takes an expression that can test the value of a property. The following example returns all processes
where the ProcessName starts with p .

PowerShell

Get-Process | Where-Object {$_.ProcessName -like "p*"}

The Get-Process cmdlet returns a collection of process objects. To filter the response, pipe the output
to Where-Object . Piping means that two or more commands are connected via a pipe | character. The
output from one command is sent as the input for the next command. The filter expression for Where-
Object uses the -like operator to match processes that start with the letter p .

Explore objects with Get-Member


Once you've been able to locate the cmdlet you want, you want to know more about what output it produces.
The Get-Member cmdlet displays the type, properties, and methods of an object. Pipe the output you want to
inspect to Get-Member .

PowerShell

Get-Process | Get-Member

The result displays the returned type as TypeName and all the properties and methods of the object. Here's an
excerpt of such a result:

Output

TypeName: [Link]

Name MemberType Definition


---- ---------- ----------
[Link] 4/5
10/30/23, 2:41 PM Discover PowerShell - PowerShell | Microsoft Learn

Handles AliasProperty Handles = Handlecount


Name AliasProperty Name = ProcessName
...

Using the MemberType parameter you can limit the information returned.

PowerShell

Get-Process | Get-Member -MemberType Method

By default PowerShell only displays a few properties. The previous example displayed
the Name , MemberType and Definition members. You can use Select-Object to specify properties you want
to see. For example, you want to display only the Name and Definition properties:

PowerShell

Get-Process | Get-Member | Select-Object Name, Definition

Search by parameter type


Get-Member showed us that Get-Process returns Process type objects. The ParameterType parameter of Get-
Command can be used to find other commands that take Process objects as input.

PowerShell

Get-Command -ParameterType Process

Output

CommandType Name Version Source


----------- ---- ------- ------
Cmdlet Debug-Process [Link] [Link]…
Cmdlet Enter-PSHostProcess [Link] [Link]
Cmdlet Get-Process [Link] [Link]…
Cmdlet Get-PSHostProcessInfo [Link] [Link]
Cmdlet Stop-Process [Link] [Link]…
Cmdlet Wait-Process [Link] [Link]…

Knowing the output type of a command can help narrow down your search for related commands.

[Link] 5/5

You might also like