In this short post I would like to share one interesting feature of the PowerShell: parameters matching by partial name. Suppose that you have the test.ps1 script with switch parameter:
If you run it in PowerShell console like this:
it will output “recreateSite” in console. Now the interesting thing is that you can run it like this:
and result will be the same. I.e. it is not necessary to specify whole name for the parameter – PowerShell will find closest match (-r corresponds to -recreateSite).
Let’s add another parameter “recreateDb”:
If you now will run it like this:
you will see the following error:
Parameter cannot be processed because the parameter name 'r' is ambiguous. Possible matches include: -recreateSite -recreateDb.
Now in order to run it you will need to use minimal name which will uniquely match some parameter. In our example:
will correspond to “recreateSite”. And:
will match to “recreateDb”.