Update:
The solution below works, but I've since come to realize that, due to a long-standing bug, it may be better to encode all arguments in a single string, because it makes the situational need for embedded double-quoting explicit - see this answer for background information; applied to the command at hand:
# Note the '...' around *all* pass-through arguments.
# This single string encoding all arguments implicitly binds to -ArgumentList
Start-Process -Wait "\\mynetworkpath\SQLServer2014SP1.exe" '/qs /IAcceptSQLServerLicenseTerms /Action=Patch /AllInstances'
Your Start-Process
call's syntax is flawed; try the following:
# Define executable
$exe = '\\mynetworkpath\SQLServer2014SP1.exe'
# Define *array* of arguments
$exeArgs = '/qs', '/IAcceptSQLServerLicenseTerms', '/Action=Patch', '/AllInstances'
Start-Process -Wait $exe -ArgumentList $exeArgs
The intermediate variables aren't strictly needed, but I've chosen them both for readability and to illustrate how the arguments fit into the Start-Process
syntax:
The pass-through arguments must be passed as an array, to the -ArgumentList
(-Args
) parameter.
The -Wait
option waits for the process created by the specified executable to terminate before moving on to the next command. Of course, this only works as intended if that process doesn't spawn other processes asynchronously that do the actual work - I don't know if that's the case with your specific executable.
With literal arguments, you could do the following, which requires less quoting:
Start-Process -Wait \\mynetworkpath\SQLServer2014SP1.exe -ArgumentList `
/qs, /IAcceptSQLServerLicenseTerms, /Action=Patch, /AllInstances
Generally, however, you need to be mindful of PowerShell's up-front interpretation of unquoted or double-quoted arguments (such as unquoted use of ,
which is interpreted as the array-construction operator), which is more extensive than cmd.exe
's - see this answer.