Forum Discussion

Mathieu_Desjardins's avatar
Mathieu_Desjardins
Brass Contributor
Apr 26, 2022
Solved

Using Start-Process with -ArgumentList

Hi everyone, I am struggling with the use of Start-Process with an argument list. It may seem obvious for some people but I find it hard to see what is going on here. I have to wait for an installa...
  • LainRobertson's avatar
    Apr 27, 2022

    Mathieu_Desjardins 

     

    Hey, Mathieu.

     

    Here's some tips:

     

    1. The escaping of the double quotes is quite broken - as you've already guessed;
    2. ArgumentList is actually a string array ([string[]]) rather than just a string.

     

    For point 1, you can either fix the escaping (the only un-escaped double quotes would be at the very start and end with everything in between being escaped) or simply avoid escaping altogether by removing all the escape characters and using single quotes around the entire ArgumentList string. This allows you to use double quotes inside the string "normally".

     

    For example, this:

     

    `"INSTALLDIR="D:\Software\App" AllUser=1 RebootYeNo="No" AddLocal="Runtime" REBOOT=ReallySuppress /qn /l*v "C:\Temp\Log.txt"`""

     

     

    Would become this (using the single quote approach):

     

    'INSTALLDIR="D:\Software\App" AllUser=1 RebootYeNo="No" AddLocal="Runtime" REBOOT=ReallySuppress /qn /l*v "C:\Temp\Log.txt"'

     

     

    Point 2 can be used to your advantage insofar as it means you can pass in smaller strings where it's much easier then to read and deal with any required escaping.

     

    For example:

     

    -ArgumentList @("/s", "/v", 'INSTALLDIR="D:\Software\App"', "AllUser=1", 'RebootYeNo="No"', 'AddLocal="Runtime"', "REBOOT=ReallySuppress", "/qn", '/l*v "C:\Temp\Log.txt"')

     

     

    It's worth noting most of your arguments don't actually need double quotes since their values don't contain spaces, so my examples above are somewhat contrived. You can simply leave all of them out.

     

    Also, is RebootYeNo meant to be RebootYesNo? I', not sure either way but figured it was worth a shout out.

     

    Cheers,

    Lain

Resources