Skip to content

Instantly share code, notes, and snippets.

@chilversc
Created May 7, 2010 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chilversc/393389 to your computer and use it in GitHub Desktop.
Save chilversc/393389 to your computer and use it in GitHub Desktop.
Powershell positional parameters
param (
[Parameter()] $foo,
[Parameter()] $bar
)
$foo
$bar
#output:
#> .\test1.ps1 0 1
#0
#1
param (
[Parameter(Position=0)] $foo,
[Parameter()] $bar
)
$foo
$bar
#output:
#> .\test2.ps1 0 1
#test2.ps1 : A positional parameter cannot be found that accepts argument '1'.
#At line:1 char:11
#+ .\test.ps1 <<<< -Foo 0 1
# + CategoryInfo : InvalidArgument: (:) [test.ps1], ParameterBindingException
# + FullyQualifiedErrorId : PositionalParameterNotFound,test.ps1
#
#> .\test2.ps1 0 -Bar 1
#0
#1
param (
[Parameter(Position=-2147483648)] $foo,
[Parameter()] $bar
)
$foo
$bar
#output:
#> .\test3.ps1 0 1
#0
#1
param (
[Parameter(Position=2147483647)] $foo,
[Parameter()] $bar
)
$foo
$bar
#> .\test4.ps1 0 1
#test4.ps1 : A positional parameter cannot be found that accepts argument '1'.
#At line:1 char:11
#+ .\test.ps1 <<<< 0 1
# + CategoryInfo : InvalidArgument: (:) [test.ps1], ParameterBindingException
# + FullyQualifiedErrorId : PositionalParameterNotFound,test.ps1
#
#> .\test.ps1 0 -Bar 1
#0
#1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment