Disable Positional Parameter Binding in Powershell

Question:

I want parameters ONLY through alias:

script.ps1 -d site1 -c eac34b2d

This shouldnt be allowed:

script.ps1 site1 eac34b2d

Answer:

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/

Source:

Disable Positional Parameter Binding in Powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply