Setting functions into function parameter in Powershell

gisliScriptingLeave a Comment

There are multiple ways to assign parameters into a function it makes sometimes the function simpler but can it make it unreadable or even the code causing errors. Now there are two examples bellow and I just wanted to show you that setting function into a function is possible, not that you would use it unless you have some awesome scenario.

Here is one that has just one parameter and ConverTo-SecureString function in the function itself, the code seems to be much more readable

Alternatively you can set function into a parameter, now you must define how much logic you use this in your own script because in some cases this is just not something you would do and here is why, in this example down bellow you can see that I have two parameters, no you would not set these two parameters but you would need to set the password parameter, if you would set both parameters you would probably get an error because the secure_string_pwd would be just plain text. Anyways this option works only if you would set one parameter and just use this approach with caution.

Good luck and I wish you a happy day

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.