Created
May 7, 2010 13:00
-
-
Save chilversc/393389 to your computer and use it in GitHub Desktop.
Powershell positional parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[Parameter()] $foo, | |
[Parameter()] $bar | |
) | |
$foo | |
$bar | |
#output: | |
#> .\test1.ps1 0 1 | |
#0 | |
#1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[Parameter(Position=-2147483648)] $foo, | |
[Parameter()] $bar | |
) | |
$foo | |
$bar | |
#output: | |
#> .\test3.ps1 0 1 | |
#0 | |
#1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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