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.