home *** CD-ROM | disk | FTP | other *** search
- TOPIC
- Script Cmdlet Methods and Properties
-
- SHORT DESCRIPTION
- Methods and properties available to script cmdlets and Begin, Process, and
- End methods.
-
- LONG DESCRIPTION
- Script cmdlets can access a number of methods and properties through the
- $cmdlet variable. These methods include the ShouldProcess met5hod used to
- get user feedback, the ThrowTerminatingError method for generating error
- records, several Write methods for emiting output from the cmdlet, and
- more. All the methods and properties available to script cmdlets are
- documented in the PSCmdlet class on MSDN.
-
-
- INPUT PROCESSING METHODS
-
- The three methods described here are referred to as the input processing
- methods of a cmdlet. In fact, this is the same for compiled and script
- cmdlets.
-
- Each script cmdlet must overwrite one or more of the three input processing
- methods. The Windows PowerShell runtime calls these methods when it is
- running the commands of a pipeline.
-
- Begin{}
- This input processing method is used to provide optional one-time, pre-
- processing functionality for the cmdlet. The Windows PowerShell runtime
- calls this method once for each instance of the cmdlet in the pipeline.
-
- Process{}
- This input processing method is used to provide record-by-record processing
- functionality for the cmdlet. This method might be called any number of
- times, or not at all, depending on the input to the cmdlet. For example, if
- the cmdlet is the first in the pipeline then it will get called once. Also,
- if the cmdlet is not the first command of the pipeline then thew Process
- method is called once for every input it receives from the pipeline. If
- there is no pipeline input then the Process method is not called.
-
- This method must be called if a cmdlet parameter is defined as accepting
- ValueFromPipeline or ValueFromPipelineByPropertyName. If this method is
- not overwritten, the cmdlet will miss the pipelined values passed to the
- cmdlet.
-
- Also, when the cmdlet supports confirmation requests (when the
- -SupportsSouldProcess attribute is declared), the call to the
- ShouldProcess method must be made from within The Process{} method.
-
- End{}
- This input processing method is used to provide optional one-time, post-
- processing functionality for the cmdlet.
-
- The following example shows the outline of a script cmdlet with
- a Begin{} method for one-time pre-processing, a Process{} method for
- multiple record processing, and an End{} method for one-time post-
- processing.
-
- Cmdlet Test-ScriptCmdlet
- -SupportsShouldProcess
- -ConfirmImpact low
- -snapin MySnapIn
-
- {
- Param ([Mandatory] $Parameter1)
- Begin{}
- Process{}
- End{}
- }
-
-
-
-
- SEE ALSO
-
- About_ScriptCmdlets
- About_ScriptCmdletAttributes
- About_ScriptCmdletParameters