home *** CD-ROM | disk | FTP | other *** search
/ Chip 2008 June / CHIP-2008-06.iso / software / PowerShell / PowerShell_Setup_x86.msi / product.cab / about_scriptcmdlets.help_EN.txt < prev    next >
Encoding:
Text File  |  2007-10-29  |  4.0 KB  |  107 lines

  1. TOPIC
  2. About Script Cmdlets
  3.  
  4. SHORT DESCRIPTION
  5. Three types of script cmdlets.
  6.  
  7. LONG DESCRIPTION
  8. Script cmdlets allow script authors to extend Windows PowerShell without
  9. relying on compiled cmdlets such as the Get-Command cmdlet. This is 
  10. helpful for script authors who want to quickly write a new cmdlet without 
  11. using a .NET framework language. Also it is helpful when they want to 
  12. restrict the functionality of a compiled cmdlet or when they simply want 
  13. to write a cmdlet that is similar to a compiled cmdlet (the differences 
  14. between compiled and script cmdlets is described later in this topic). 
  15.  
  16. Compiled cmdlets are .NET classes that must be written in a .NET framework 
  17. language such as C#. In contrast, script cmdlets are written in the 
  18. Windows PowerShell script language in the same way that functions or other 
  19. script blocks are written. In fact, a script cmdlet can be considered a 
  20. specialized script block.
  21.  
  22. There are two types of script cmdlets: named script cmdlets that have the 
  23. same Verb-Noun name as compiled cmdlets, and unnamed script cmdlets. 
  24. However, both types use the "cmdlet" keyword to identify them as cmdlets.
  25.  
  26. The following example shows the outline of a named script cmdlet that 
  27. supports should-process calls, and has two parameters with the first 
  28. paramater being a mandatory parameter. Also notice that the name of the 
  29. cmdlet includes a verb and noun pair. 
  30.  
  31. Cmdlet Verb-Noun
  32.   -SupportsShouldProcess
  33.   {
  34.     Param ([Mandatory] $Parameter1, Parameter2)
  35.     Begin{}
  36.     Process{}
  37.     End{}
  38.   }
  39.  
  40. In the previous example, the Begin{}, Process{}, and End{} methods are 
  41. equivalent to the process record methods used by compiled cmdlets. These 
  42. methods are described in the about_ScriptCmdletMethods topic.
  43.  
  44. The following example shows the outline of the same cmdlet previouly 
  45. shown, yet in this implementation the cmdlet is an unnamed script cmdlet.
  46.  
  47. {
  48.   Cmdlet
  49.   -SupportsShouldProcess
  50.   {
  51.     Param ([Mandatory] $Parameter1, Parameter2)
  52.     Begin{}
  53.     Process{}
  54.     End{}
  55.   }
  56. }
  57.  
  58. Both types of script cmdlets, named and unnamed script cmdlets, can also be 
  59. written within a script file. However there are differences. When a named 
  60. script cmdlet is written within a script file, running the script file only 
  61. declares the script as a cmdlet. The cmdlet is not invoked. In contrast, 
  62. When an unnamed script cmdlet is written within a script file, running the 
  63. script file does invoke the cmdlet.
  64.  
  65. For additional information on script cmdlets, read the topics in Related 
  66. Links, or look at "Windows PowerShell Cmdlets" in the Windows PowerShell 
  67. Programmer's Guide on MSDN (the content on MSDN is written for developers 
  68. who are writing compiled cmdlets, yet the concepts are the same for script 
  69. authors writing script cmdlets.)
  70.  
  71.  
  72. DIFFERENECES BETWEEN SCRIPT AND COMPILED CMDLETS
  73.  
  74. Here are some of the characteristics of script cmdlets that differ from 
  75. the characteristics of compiled cmdlets. 
  76.  
  77.   The command "get-command <cmdletname>" returns a command type of 
  78.   "Filter", not "Cmdlet". For that reason the command "get-command" 
  79.   (with no parameters) does not return script cmdlets, only compiled 
  80.   cmdlets are returned. Also, the command "get-command -syntax" does 
  81.   not return syntax information for script cmdlets. 
  82.  
  83.   Script cmdlet parameter binding does not bind an integer value from 
  84.   the pipeline to a string[] parameter.
  85.  
  86.   Script cmdlet parameter binding does not throw an exception when 
  87.   binding an array of strings to a Boolean[] parameter.
  88.  
  89.   The ValidateSet attribute and ValidatePattern attribute cannot pass 
  90.   named parameters.
  91.  
  92.   The ArgumentTransformation attribute is not working in the pre-release 
  93.   version of Windows PowerShell, version 2.0.
  94.  
  95.   When using multiple parameter sets, sharing parameters between 
  96.   parameter sets is not working in the pre-release of Windows PowerShell, 
  97.   version 2.0.
  98.  
  99.   Script cmdlets do not support Help files.  
  100.  
  101.  
  102.  
  103. SEE ALSO
  104.  
  105. About_ScriptCmdletAttributes
  106. About_ScriptCmdletMethods    
  107. About_ScriptCmdletParameters