Given a script foo.ps1: param($x,$y) return $x/$y
Is it possible to enforce explicit parameter naming when calling it?
./foo.ps1 5 10 would generate an error ./foo.ps1 -x 5 -y 10 would be OK
This code works but it uses something not documented (I could not find anything about negative positions):
function Test
{
param(
[Parameter(Position=-1)]
$x
,
[Parameter(Position=-1)]
$y
)
$x/$y
}
Test -x 1 -y 2
Test -y 2 -x 1
Test 1 2
Output:
0.5
0.5
Test : Cannot bind positional parameters because no names were given.
At C:\TEMP\_110127_170853\q1.ps1:15 char:5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With