Positional Parameters in Power Shell: understand them but don’t over use them


positional-parameters

 

This PosH guru blog makes a good point; use Positional parameters in a interactive PoSh console but don’t use in scripts. Your goal is to write a better, clear and consistent code and positional parameters is more of a shortcut if you are in a worry but not considered best practices.

“Explanation: Positional and partial parameter names can be used for the interactive Powershell console to speed up our work, but not in scripts.

It takes more time to write the named parameter but your code will be more clear and consistent.

Positional parameters can be more difficult to read especially with cmdlets supporting multiple parameters.
Besides, the command will fail if the correct order is not respected (parameter order mixed up).

Moreover, with future versions of Powershell there is no guarantee that these parameters keep the same position.
A script created using positional parameters in the past could have a different behaviour in the future, but with named parameters there is no issue.

You can use Show-Command to see the Best Practice action as it will use the full cmdlet name and the named parameter.” source: PoSh guru

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: