Behind the PowerShell Pipeline logo

Behind the PowerShell Pipeline

Subscribe
Archives
May 2, 2023

Parameter Power

When creating a PowerShell function, you've often heard me say, "Think about who will use it and what are their expectations?" As a corollary, you want to reduce as much friction as possible. In other words, make it as easy to use as possible. You never want to force the user to jump through hoops. It is your job to write a command that is easy to understand and use.

One step you can take is to make it easy to pass parameter values. Because you want your command to be as flexible and reusable as possible, don't be afraid to parameterize anything a user might want to change, even if only 10% of the time. In those cases, provide a default parameter value.

[string]$Computername = $env:Computername

But what about the rest of your function's parameters? Are there things you can do to make it easy for the user to specify a valid value? That's what I want to show you today.

Want to read the full issue?
GitHub Bluesky LinkedIn About Jeff
Powered by Buttondown, the easiest way to start and grow your newsletter.