Reputation: 439
I've recently been asked to modify some powershell scripts, and I've a good understanding of the concept with variables and $. But I don't quite understand what this piece of code does and works:
[string]$env = $(throw "-env is required.)
To be more precise I wonder about the single $ sign, and the throw keyword.
/Andy
Upvotes: 2
Views: 44
Reputation: 144126
It is being used to make the $env parameter mandatory. [env]$env = "default"
will assign "default" to env if no value is provided.
throw "error"
is used to throw an exception.
Therefore [string]$env = $(throw "-env is required.")
will throw an exception if no value is provided by the user.
Upvotes: 4