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
)
Basically you want to disable positional parameter binding. I wrote about a built-in way in Powershell 3.0: use [CmdletBinding(PositionalBinding=$false)]
.
A workaround for v2 is available here:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.