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.
Passing parameters to exe
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Passing parameters to exe
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.
The functions are basically PowerShell versions to the standard "C" command parsers.
Re: Passing parameters to exe
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...
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
Here is an example.
Build and test with
.\TestArgs.exe -test 456789
Build and test with
.\TestArgs.exe -test 456789
- Attachments
-
- TestArgs.ps1
- (8.84 KiB) Downloaded 232 times
Re: Passing parameters to exe
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.
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
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.