On Jun 27, 7:27*am, Jacob Saaby Nielsen <jacob.sa...@xxxxxx>
wrote:
Quote:
> Hey,
>
> perhaps I should supply an example.
>
> Let's say TestScript had 10 possible parameters you could pass to it.
>
> E.g. "TestScript /whatever:0 /morewhatever:4 /evenmorewhatever:hellno" and
> so forth.
>
> How do you:
>
> 1. Best make the script do what it should do, based on the values in those
> parameters
> 2. Any difference to using /command, -command or something else ? Does PS
> require something particular here ?
> 3. How do you best make the script avoid the parameters NOT set ? E.g. in
> the above example, 7 are missing of the 10 - how do you stick to the script
> JUST using the 3 that are used ?
>
> I'm looking for any and all ways to do it, since it's simply for inspiration
> for finding a way that works (for me), and I was kinda wondering 
>
> Best Regards,
> Jacob Saaby Nielsen
>
> http://www.ijacob.info
> gmail: jacob DOT saaby
> hotmail (IM/LinkedIN/Facebook): same as gmail
>
>
>> Quote:
> > anyone got any good way to handle parameters to a script ?
> Quote:
> > E.g. the script takes certain parameters.
> > What's the best way to check if they're set, and if they are to use
> > them,
> > if they're not, how to not use them.
> > Anybody did something they wanna share in that regard ?
> Quote:
> > I'm thinking something that builds a command, but there might be a
> > much better way.
> Quote:
> > Please share how you accomplish this 
> Quote:
> > Best Regards,
> > Jacob Saaby Nielsen
> >http://www.ijacob.info
> > gmail: jacob DOT saaby
> > hotmail (IM/LinkedIN/Facebook): same as gmail- Hide quoted text - >
> - Show quoted text - The example you give shows 'executable' style parameters
rather than PowerShell style. I'm not sure it's clear if you
intend PowerShell to interpret the parameter syntax you've
presented or need it to built the parameter string for an
executable.
PowerShell doesn't deal with parameters the same way typical
executables do. If, as I suspect, you are looking to interpret
stuff like this being passed to your routine you really need to
have a good reason because it won't be easy. If you can pass
your parameters in the PowerShell supported way it's very easy.
TestScript -whatever 0 -morewhatever 4 -evenmorewhatever hellno
function TestScript ([int]$whatever = -1, [int]$morewhatever = -1
[string]$evenmorewhatever = '', $anything) {
if ($anything -eq $null){"anything not passed"}
...}