Skip to content

PowerShell Cmdlets and Syntax

PowerShell is made up of thousands of cmdlets (command-lets). Cmdlets consist of a verb and a noun. For example, you can use the Get-Location cmdlet to know or confirm the current working directory. Get is the verb, and Location is the noun.

PowerShell is a robust, object-oriented language for automation, server management, documentation, and information gathering.
PowerShell is a robust, object-oriented language for automation, server management, documentation, and information gathering. Microsoft’s goal was to replace the Windows GUI for serious system administration. Modern Windows systems would run using server core (no GUI): managed from secure remote terminals using only PowerShell. While Windows administrators continue to embrace GUI-driven administration, they are also adopting PowerShell increasingly for its ease of use and rich set of commands.

By changing the verb to Set, we can move to another directory…

PowerShell is object-oriented. Cmdlets are objects, and the output from a cmdlet is also an object.  Even variables are objects! Objects support methods which are actions that you can perform on a given object using dot notation. For example, let’s assign the text “Hello World” to a variable called $hello (variables in PowerShell are denoted using the $ sign):

If we want to know or confirm what $hello is, we can use the .GetType() method, which shows us that $hello is a string.

If we want to know how long $hello is, we can use the .Length method to find that $hello is 11 characters long.

If we wanted to know if $hello contains the string “Hello” we can use the .Contains() method as shown below.

PowerShell is loosely typed, meaning it will make assumptions about data types for you. You do not need to declare what a variable is beforehand. In the example above, $hello is a string. However, we did not have to tell PowerShell that $hello is a string. In the example below, PowerShell assumes the number 1 is a 32-bit integer.

PowerShell supports piping. Piping means that one cmdlet’s output can become another’s input.  For example, what if we want to see every method available to our Int32 variable $a? We can pipe $a to the Get-Member cmdlet, as shown below.

What if we wanted to count how many methods there are? We can pipe our output again to the Measure-Object cmdlet, as shown below.

What if we only wanted the Count? We can pipe one more time using Select-Object cmdlet, as shown below.

Leave a Reply

Your email address will not be published. Required fields are marked *