What is cmdlet




















PowerShell, the object-oriented programming language and interactive command line shell for Microsoft Windows, is a great tool for automating Microsoft Windows system tasks. Besides that, it can be used for management of third-party applications, if that is envisioned by their developers. PowerShell lets administrators perform administrative tasks on both local and remote Windows systems.

Those tasks are performed by using PowerShell cmdlets command-lets , which are special simple commands, consist of two words — a verb and a noun — executing a simple function. Cmdlets can be grouped and used for writing advanced scripts and even executable applications. The first version of this framework became available in as an optional Windows Server or Windows XP SP2 component and became completely integrated into all later OS releases.

Currently, Windows Server R2 and Windows 8. Figure 1. There are several reasons to consider using the PowerShell command line interface, but here are my top three. Run an old-fashioned command line cmd. Or, you can hit the PowerShell icon on the taskbar. Figure 2. Windows PowerShell console. Another important cmdlet is Get-Command. A cmdlet can have multiple parameter sets, but each parameter set must have at least one parameter that is unique.

Good cmdlet design strongly suggests that the unique parameter also be a required parameter. For more information about parameter sets, see Cmdlet Parameter Sets. A parameter that is added to the cmdlet at runtime. Typically, the dynamic parameters are added to the cmdlet when another parameter is set to a specific value. For more information about dynamic parameters, see Cmdlet Dynamic Parameters. The System. Cmdlet class provides the following virtual methods that are used to process records.

All the derived cmdlet classes must override one or more of the first three methods:. For more information about these methods, see Cmdlet Input Processing Methods. When you implement a cmdlet, you must override at least one of these input processing methods. Typically, the ProcessRecord is the method that you override because it is called for every record that the cmdlet processes.

In contrast, the BeginProcessing method and the EndProcessing method are called one time to perform pre-processing or post-processing of the records. For more information about these methods, see Input Processing Methods.

PowerShell allows you to create cmdlets that prompt the user for feedback before the cmdlet makes a change to the system. To use this feature, the cmdlet must declare that it supports the ShouldProcess feature when you declare the Cmdlet attribute, and the cmdlet must call the System. ShouldProcess and System. ShouldContinue methods from within an input processing method. For more information about how to support the ShouldProcess functionality, see Requesting Confirmation.

A logical group of commands that are treated as a single task. The task automatically fails if any command in the group fails, and the user has the choice to accept or reject the actions performed within the transaction. To participate in a transaction, the cmdlet must declare that it supports transactions when the Cmdlet attribute is declared. Support for transactions was introduced in Windows PowerShell 2. For more information about transactions, see How to Support Transactions. Most cmdlets are based on.

NET classes that derive from the System. Cmdlet base class. Deriving from this class allows a cmdlet to use the minimum set of dependencies on the Windows PowerShell runtime. This has two benefits. The first benefit is that the cmdlet objects are smaller, and you are less likely to be affected by changes to the PowerShell runtime. The second benefit is that, if you have to, you can directly create an instance of the cmdlet object and then invoke it directly instead of invoking it through the PowerShell runtime.

The more-complex cmdlets are based on. PSCmdlet base class. Deriving from this class gives you much more access to the PowerShell runtime. This access allows your cmdlet to call scripts, to access providers, and to access the current session state.

To access the current session state, you get and set session variables and preferences. However, deriving from this class increases the size of the cmdlet object, and it means that your cmdlet is more tightly coupled to the current version of the PowerShell runtime.

In general, unless you need the extended access to the PowerShell runtime, you should derive from the System. Cmdlet class. It's important to put the file or directory name in quotes if it contains spaces, as we have done in these examples. The Get-Location cmdlet tells you what your current directory is.

For instance:. The Set-Location cmdlet changes the working directory to one you specify. For more information and examples of cmdlets to use in Microsoft PowerShell, Microsoft maintains a PowerShell documentation site. It provides details about PowerShell, including cmdlets and help on how to use the cmdlets in scripts on your system.

Command line , Operating system terms , Windows.



0コメント

  • 1000 / 1000