Page 2 of 2

Re: Passing parameters to exe

Posted: Fri Oct 23, 2015 2:04 am
by fergusfog
Thanks for your help.

Maybe I'm confused by the first part ending with:

Results:

$Parameter[0] = –Parameter

and then continuing with:

It can be taken even further by creating a function called Convert-ArgumentsToDictionary...

This tells me the bit that follows is optional, but you seem to be suggesting the 2nd (Dictionary) part is required as well..?

For that reason, I was taking the first bit only and trying to make that work. I'll give it a go with the rest too.

Re: Passing parameters to exe

Posted: Fri Oct 23, 2015 2:30 am
by jvierra
The ony part that is default is handing the copy of the command line. You have to call the functions to get a dictionary. YO also have to understand what arguments are and how they are used programmatically.

The functions are basically PowerShell versions to the standard "C" command parsers.

Re: Passing parameters to exe

Posted: Sun Oct 25, 2015 12:51 pm
by fergusfog
Okay, I'm almost there and understanding it a little more.

The last bit, however, is not giving me any output.

Your previous post with:
$myargs=Parse-Commandline $CommandLine
#Convert the Arguments. Use – as the Argument Indicator
$named=Convert-ArgumentsToHashtable $myargs ‘-‘

Well, I copied the code from the article so I'm using $dictionary instead of $named, but trying to get the value for the -imei arg I passed to the exe doesn't give me anything. I'm running the exe with "-imei 333333", so I'm trying to get the code to return "33333333" for me:
$1 = $Dictionary['imei']
Write-Host $1
but this is empty.

(Btw it does output $dictionary in a nice formatted table, so the data is in there, but I just have the wrong code to get it out.)

When this is done, I'm investing in a PS book...

Re: Passing parameters to exe

Posted: Sun Oct 25, 2015 1:24 pm
by jvierra
Here is an example.

Build and test with

.\TestArgs.exe -test 456789

Re: Passing parameters to exe

Posted: Sun Oct 25, 2015 2:10 pm
by fergusfog
Wow. Excellent. Many thanks for all your help.

I've incorporated it into my MSOnline scripts and it works like a charm.

Tbh I can't see what's different from what I was doing, but I'm not complaining. :-)

Cheers again.

F.

Re: Passing parameters to exe

Posted: Sun Oct 25, 2015 2:42 pm
by jvierra
Great. The discussion may be a bit confusing if you are not up to speed in PowerShell. I just grabbed everything and ran it. The original code I posted was a mix of both techniques an was probably misleading and wouldn't have worked if you didn't have all (new and old) functions loaded.