C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
What is PowerShell Cmdlet?A cmdlet 'pronounced as a command-lets' is a lightweight command which is used in the PowerShell environment. These are the special commands in the PowerShell environment which implements the special functions. The cmdlets follow a 'verb-noun' pattern, such as 'set-childItem'. Windows PowerShell runtime invokes these commands in the context of automation scripts which are provided at the command line. It also invokes them programmatically through Windows PowerShell Application Programming Interfaces APIs. CmdletsThe cmdlets in a PowerShell perform an action and returns a Microsoft .NET framework object to the next command in the pipeline. Cmdlets can receive objects as input and can also output their results as objects, which makes them suitable for use as recipients in a pipeline. If you write a cmdlet, you must implement a cmdlet class which derives from one of two specialized cmdlet base classes. A derived class must:
Cmdlet TermsThe terms which are used frequently in the Windows PowerShell cmdlet are as follows: Cmdlet attributeWindows PowerShell defines several attributes which are used to add common functionality to the cmdlets. It includes the cmdlet attribute which identifies a Microsoft .NET framework class as a cmdlet class. Cmdlet ParametersIt provides the mechanism which allows the cmdlet to access the input. Parameters can accept input directly from the command line, or the objects passed to the cmdlet through the pipeline. Parameter SetA group of parameters are used in the same command to perform a particular action. A cmdlet in a PowerShell can have multiple parameter sets, but each parameter set must have at least one unique parameter. Windows PowerShell uses parameter sets allow you to write a single cmdlet which can do different actions for different scenarios. Parameter sets will enable you to expose different parameters to a user, and based on the parameters; it returns different information specified by the user. Dynamic ParameterDynamic parameters are added to the cmdlet at runtime. Typically, when the argument of another parameter is set to a particular value, then these arguments are added to cmdlet. Input Processing methodInput processing methods allow the cmdlet for performing the operations of input processing, pre-processing, and post-processing. Those methods that a cmdlet uses to process a record it receives as an input. The input processing method includes the System.Management.Automation.Cmdlet.EndProcessing method, System.Management.Automation.Cmdlet.ProcessRecord method, and System.Management.Automation.Cmdlet.BeginProcessing method. TransactionThe logical group of commands are treated as a single-task. The task automatically fails, if any of the command in the group fails. And a user has the choice to reject or accept the actions performed within the transactions. Support to transactions was introduced in Windows PowerShell version 2.0. How Cmdlet differ from commandsThe cmdlets differ from the commands in other command shell environments in the following ways:
Next TopicBasic cmdlets of PowerShell
|