Wednesday, October 28, 2015

Defining Parameters for PowerShell scripts

If you need to define arguments or parameters for your PowerShell scripts, you will want to take a look at this article: https://technet.microsoft.com/en-us/magazine/jj554301.aspx

Personally, when I define parameters for my PowerShell scripts, I prefer to use the [CmdletBinding()] syntax since it is more clear about the types of parameters as well as the order in which they need to appear.  I also receive meaningful error messages when I fail to pass in a parameter to my PowerShell script.

If you want to further manage your parameters, you can use Default Values for your parameters as outlined here: http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/21/create-and-use-default-values-in-powershell-scripts.aspx

 

No comments:

Post a Comment