Demonstrates Parameter attribute usage in PowerShell V2 CTP3


posted by Thomas Lee
12-29-2008

Downloads: 457
File size: 1.9kB
Views: 3,311

Embed
Demonstrates Parameter attribute usage in PowerShell V2 CTP3
  1. <#fee 
  2. .SYNOPSIS 
  3.     Shows Parameter attributes 
  4. .DESCRIPTION 
  5.     Script is decorated with Parameter attributes to demostrate the use of them 
  6. .NOTES 
  7.     File Name  : Get-ParameterAttribute1.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell V2 CTP3 
  10. .LINK 
  11.     To be posted at: 
  12.     http://www.pshscripts.blogspot.com 
  13. .EXAMPLE 
  14.     Simple usage, with partial parameters specified 
  15.     PS C:\foo> .\Get-ParameterAttribute1.ps1 abc 
  16.     ---- 
  17.     Domain    : abc 
  18.     Computer  : Cookham8 
  19.     User      : tfl 
  20.     ---- 
  21. .EXAMPLE 
  22.     Simple usage, with all parameters specified 
  23.     PS C:\foo> .\Get-ParameterAttribute1.ps1 kapoho, kapoho1, BigKahuna 
  24.     ---- 
  25.     Domain    : kapoho 
  26.     Computer  : kapoho1 
  27.     User      : BigKahuna 
  28.     ---- 
  29. .EXAMPLE 
  30.     Showing getting first parameter from the pipeline 
  31.     PS C:\foo> "abc", "def", "GHI" |.\Get-ParameterAttribute1.ps1 
  32.     ---- 
  33.     Domain    : abc 
  34.     Computer  : Cookham8 
  35.     User      : tfl 
  36.     ---- 
  37.     ---- 
  38.     Domain    : def 
  39.     Computer  : Cookham8 
  40.     User      : tfl 
  41.     ---- 
  42.     ---- 
  43.     Domain    : GHI 
  44.     Computer  : Cookham8 
  45.     User      : tfl 
  46.     ---- 
  47. EXAMPLE 
  48.     Shows getting all Value From Remaining Arguments 
  49.     PS C:\foo> .\Get-ParameterAttribute1.ps1 abc def ghi xxx xxx xxx xxx 
  50.     ---- 
  51.     Domain    : abc 
  52.     Compuyter : def 
  53.     User      : ghi xxx xxx xxx xxx 
  54. .PARAMETER Domain 
  55.     A domain name - must be a string 
  56. .PARAMETER Computer 
  57.     A computer Name - must be a string 
  58. .PARAMETER User 
  59.     A user name - must be a string 
  60. #> 
  61. param
  62. [Parameter(Position=0, Mandatory=$true,ValueFromPipeLine=$true)] 
  63. [string] $Domain = "Cookham" ,     
  64. [Parameter(Position=1, Mandatory=$false)] 
  65. [string] $Computer = "Cookham8"
  66. [Parameter(Position=2, Mandatory=$false, ValueFromRemainingArguments=$true)] 
  67. [string] $User     = "tfl"             
  68.  
  69. Process { 
  70. "----" 
  71. "Domain    : {0}" -f $domain 
  72. "Computer  : {0}" -f $computer 
  73. "User      : {0}" -f $user 
  74. "----" 
This script is decorated with Paramater Attributes and the Example block show sample usage.This script is described in more detail on my main blog (http://tfl09.blogspot.com) publised 3 Jan. See the examples in this script for more clues into how ths works!
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.