I want parameters ONLY through alias:
script.ps1 -d site1 -c eac34b2d
This shouldnt be allowed:
script.ps1 site1 eac34b2d
Param(
[parameter(Mandatory=$true)]
[alias("d")]
$DocRoot,
[alias("c")]
$Commit
)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Basically you want to disable positional parameter binding. I wrote about a built-in way in Powershell 3.0: use
[CmdletBinding(PositionalBinding=$false)].http://blogs.microsoft.co.il/blogs/scriptfanatic/archive/2011/09/19/how-to-disable-positional-parameter-binding-in-powershell.aspx
A workaround for v2 is available here:
http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/abbc587f-cd7e-4c8d-879f-355339d9d6b7/