Powershell 101 | Cmdlets and parameters with examples

What are Cmdlets?

Cmdlets are PowerShell commands. They are the backbone of PowerShell. PowerShell starts with cmdlets.

A cmdlet is always presented in a verb-noun pair format.

Syntax: Verb-Noun

For example the command Get-Service will retrieve all services on your system:

The command Get-Service retrieved all services on my system.
(click on the image to open in a new tab)

Every cmdlet does something. Something specific. It performs an unique action, and not a multitude of things.

In our previous example it retrieves (Get) all the services on our system.

Cmdlets are native to Powershell. That means they already exists and we just have to choose which one to use for our specific need.

We can suffle through the available cmdlets by using the tab key.
Every time we tab a different cmdlet is proposed.

Suffling through the available cmdlets by using the tab key.
Note: If tab too fast and jump the desired cmdlet, you can use Shift+Tab to return back.

Properties and Parameters

Cmdlet Parameters

Let’s say that we want to see a specific service on our screen. Not all of them.
We can achieve this by using a cmdlet’s parameter.
Parameters provide more information about specific cmdlets and they can control their behavior. Each cmdlet has its own parameters.

So the syntax of cmdlet parameter is as follows.

Cmdlet -Parameter

Parameter’s values that are of type string must be included in quotes if that string has spaces.

String parameters must be included in quotes.
(click on the image to open in a new tab)

Ignoring this rule will get us a warning:

The Avast Firewall Service should be inside quotes.
(click on the image to open in a new tab)

Cmdlet Properties

We have already seen that with the Get-Service cmdlet gets all our systems services. These services are retrieved in the form of three different columns, each one having a distinct title.

We call these titles properties.

A property is an attribute of an object returned by a cmdlet. It’s part of the data structure.

Properties are part of the object returned, not the command input.

We have seen so far the execution of the Get-Service command and we noticed that one column is named after the property Name.

Here, Status, Name, and DisplayName are properties.
(click on the image to open in a new tab)

So let’s use the parameter Name to display a specific service. Here we guess that there is a synonymous parameter, since there is a property with the same Name.

This is a calculated guess but if we want to be sure about a parameter we can see all available parameters with:

Get-help Get-Service -Full, will get us all the available parameters for that cmdlet.
(click on the image to open in a new tab)

I type get-service-name brave and the brave service is printed on the screen.
The third word (brave here) is the value of the parameter.

Brave’s properties are printed on screen.
(click on the image to open in a new tab)
Note: Capitalization is not mandatory. The powershell commands are case-insencitive.

Although my blog doesn’t support comments, feel free to reply via email or X.

Privacy Policy Lambros Hatzinikolaou © 2024 — Today. All rights reserved.