"You can tell Windows PowerShell to expect these parameters, collect them from the command line, and put their values into variables within your script or function. That makes dealing with input easy and efficient.
You just have to know how to declare your parameters. The simplest means of doing so is the param block:
And that's just great, but I have a question; why did declare the variable types like that? ([string])
Is it necessary? Does it provide any added functionality or prevent potential problems?
by DonJ at 2013-02-09 12:45:06
It isn't necessary, but it (a) ensures I get a string – as opposed to a Service object or something else – in the parameter, and (b) helps document what the parameter expects for anyone running the command. PowerShell uses that to construct a basic default help display, for example.
The topic ‘Why declare a variable type for Powershell parameters?’ is closed to new replies.