home *** CD-ROM | disk | FTP | other *** search
- TOPIC
- About Script Cmdlets
-
- SHORT DESCRIPTION
- Three types of script cmdlets.
-
- LONG DESCRIPTION
- Script cmdlets allow script authors to extend Windows PowerShell without
- relying on compiled cmdlets such as the Get-Command cmdlet. This is
- helpful for script authors who want to quickly write a new cmdlet without
- using a .NET framework language. Also it is helpful when they want to
- restrict the functionality of a compiled cmdlet or when they simply want
- to write a cmdlet that is similar to a compiled cmdlet (the differences
- between compiled and script cmdlets is described later in this topic).
-
- Compiled cmdlets are .NET classes that must be written in a .NET framework
- language such as C#. In contrast, script cmdlets are written in the
- Windows PowerShell script language in the same way that functions or other
- script blocks are written. In fact, a script cmdlet can be considered a
- specialized script block.
-
- There are two types of script cmdlets: named script cmdlets that have the
- same Verb-Noun name as compiled cmdlets, and unnamed script cmdlets.
- However, both types use the "cmdlet" keyword to identify them as cmdlets.
-
- The following example shows the outline of a named script cmdlet that
- supports should-process calls, and has two parameters with the first
- paramater being a mandatory parameter. Also notice that the name of the
- cmdlet includes a verb and noun pair.
-
- Cmdlet Verb-Noun
- -SupportsShouldProcess
- {
- Param ([Mandatory] $Parameter1, Parameter2)
- Begin{}
- Process{}
- End{}
- }
-
- In the previous example, the Begin{}, Process{}, and End{} methods are
- equivalent to the process record methods used by compiled cmdlets. These
- methods are described in the about_ScriptCmdletMethods topic.
-
- The following example shows the outline of the same cmdlet previouly
- shown, yet in this implementation the cmdlet is an unnamed script cmdlet.
-
- {
- Cmdlet
- -SupportsShouldProcess
- {
- Param ([Mandatory] $Parameter1, Parameter2)
- Begin{}
- Process{}
- End{}
- }
- }
-
- Both types of script cmdlets, named and unnamed script cmdlets, can also be
- written within a script file. However there are differences. When a named
- script cmdlet is written within a script file, running the script file only
- declares the script as a cmdlet. The cmdlet is not invoked. In contrast,
- When an unnamed script cmdlet is written within a script file, running the
- script file does invoke the cmdlet.
-
- For additional information on script cmdlets, read the topics in Related
- Links, or look at "Windows PowerShell Cmdlets" in the Windows PowerShell
- Programmer's Guide on MSDN (the content on MSDN is written for developers
- who are writing compiled cmdlets, yet the concepts are the same for script
- authors writing script cmdlets.)
-
-
- DIFFERENECES BETWEEN SCRIPT AND COMPILED CMDLETS
-
- Here are some of the characteristics of script cmdlets that differ from
- the characteristics of compiled cmdlets.
-
- The command "get-command <cmdletname>" returns a command type of
- "Filter", not "Cmdlet". For that reason the command "get-command"
- (with no parameters) does not return script cmdlets, only compiled
- cmdlets are returned. Also, the command "get-command -syntax" does
- not return syntax information for script cmdlets.
-
- Script cmdlet parameter binding does not bind an integer value from
- the pipeline to a string[] parameter.
-
- Script cmdlet parameter binding does not throw an exception when
- binding an array of strings to a Boolean[] parameter.
-
- The ValidateSet attribute and ValidatePattern attribute cannot pass
- named parameters.
-
- The ArgumentTransformation attribute is not working in the pre-release
- version of Windows PowerShell, version 2.0.
-
- When using multiple parameter sets, sharing parameters between
- parameter sets is not working in the pre-release of Windows PowerShell,
- version 2.0.
-
- Script cmdlets do not support Help files.
-
-
-
- SEE ALSO
-
- About_ScriptCmdletAttributes
- About_ScriptCmdletMethods
- About_ScriptCmdletParameters