PowerShell Commands, also called Commandlets or Cmdlets, are the smallest unit of the PowerShell scripting language, consisting of a verb, a noun and a parameter list.
PowerShell Commandsare based on structural verb-noun name conventions, same goes for their derived Microsoft .NET Framework classes. The name convention with two componentsexponentially increases the number of possible combinations while reducing the number of base commands one must know thus supporting the main idea of PowerShell being a rather easy and literal scripting language.
In this article the basic structure of these commands will be recalled with a few examples and Verb Naming Rules will be presented in a brief form. To get a general overview about the PowerShell scriptingbasics, visit the article on PowerShell Scripting Language.
Structure of PowerShell Commands
PowerShell Cmdlets are single, light-weight commands. They can also be invoked by their regarding aliases. They serve two basic functions: perform an action and return an object to a pipeline.
Similar to real pipelines, pipelines in PowerShell connect different segments and what is entering is exiting. Controlled by the pipe operator “|” does exactly that: the output of the first command operates as the input of the subsequent command. Despite PowerShell showing text on-screen, PowerShell does pipe objects and not texts between commands.
Or, verbalized: PowerShell commands obey a Do-AThing structure, with a couple of effects: on the one hand, modular commands are easier to remember than individual commands themselves, on the other hand it allows cross inference and stretches the limit of known commands even further. Described descriptively: If a known Noun works with let us say the Verb “Get”, chances are high it works with “Set” too, even if unknown yet.
Approved Verbs for PowerShell Commands
Verb Naming Rules are quite important for commands: using predefined verb names provided by PowerShell and refining the action with the use of parameters ensure consistency in naming, the same goes for using Pascal Casing (capitalized initial letters).
A certain alias prefix is signed to each approved verb. It is used to name aliases for commands using that verb. This though, must not be respected for command aliases mimicking well known PowerShell commands from other environments.
Parameters can be used on cmdlets, functions, and scripts to provide additional input by the user. As for a PowerShell command,they mainly extend or narrow down the effect of it.
In general, parameters have in common modifying a command, but their approach and effect differ, e.g., so-called switch parameter do not require a value. (If specified, the value is true, otherwise false).
CommonParameters specifies a set of cmdlet parameters that can be used on any cmdlet, as they are implemented by PowerShell and not the cmdletprovider/developer, making them runnable on all PowerShell Commands. Keep in mind that running into no errors does not equal results of value as some CommonParameters have no effect on some cmdlets.
Parameters can be used for much more though. In an AdvancedFunction, parameters affect the function and with arguments limit the parameter values that function users submit with the parameter. CommonParameters are also available on advanced functions that make use of one of the attributes “CmdletBinding“ or “Parameter“.