PowerShell – General cmdlet constructs

Cmdlet structure

And so to a discussion on cmdlet structure.

PowerShell use a verb noun structure which may be followed by some parameters. Parameters are not compulsory as we saw in the help section but knowing how the commands maybe structured can help find the right one

verb-noun -parameter1 -parameter2

Common verbs in use

  • Get
  • Set
  • Add
  • Remove
  • New

Common nouns would be for windows components for example

  • Service
  • Process
  • EventLog
  • ChildItem

So the command to get information about the services on the local computer would be

Get-Service
The output of Get-Service cmdlet

To get information about an individual service you would add that as a parameter

Get-Service -Name Spooler
The output of Get-Service cmdlet for the spooler service

We can create things with verbs like New

and add content to them with verbs like Add

Do you remember the Get-Command cmdlet we mentioned in the help post? You can use that to help you find things with a particular verb like this

Get-Command get-*
Get-Command Set-*
Get-Command Add-*

If you wanted to narrow that down to a particular noun, you can just make the wildcard a but more specific

Get-Command get-*network*
Get-Command Set-*network*
Get-Command Add-*windows*

You’ll also see in the lists these commands produce whether they are and alias or a PowerShell cmdlet. Do you remember what an Alias is? If not go back and re-read this lesson

Conclusion

cmdlets are made up of a verb (action) and a noun (thing) and all we are doing is telling PowerShell to do something and what to do it on. Get something about, add something to, set something on … it is really that simple.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.