Powershell: Validating Parameters Using Private Functions

Mike Robbins shows how to split out validation from your primary function within Powershell:

They responded by asking if it was possible to move the custom message that Throw returns to the private function. At first, I didn’t think this would be possible, but decided to try the code to make an accurate determination instead of just assuming it wasn’t possible.

I’ve now learned something else which makes the whole process of moving the validation from the ValidateScript block to a private function much more user friendly which is what I think the person who asked the question was trying to accomplish.

If you have several parameters with somewhat complex validation logic, this makes maintenance a lot easier.

Related Posts

Exporting Table Details With Powershell

Andy Levy helps an end user understand a database schema: This week I had a user come to me asking about how fields were defined on a few tables he was using in writing some reports. Long story short, he’s been tasked with writing some new reports and updating existing ones, but he doesn’t have […]

Read More

Config Options For Checks In DBAChecks

Rob Sewell explains a new features in dbachecks: You can see the name, the current value and the description Ah thats cool he said so How Do I Know Which Configuration Is For Which Check? Well, you just…. , you know…… AHHHHHHH Rob then made this possible.  Click through to see how you can determine […]

Read More

Categories

April 2018
MTWTFSS
« Mar May »
 1
2345678
9101112131415
16171819202122
23242526272829
30