Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working on a script that calls a program passing varying parameters. I'd like to build up the parameters as a string, something like:

$parameters = "";
if ($condition2) {
    $parameters = $parameters + " /include:hi /exclude:low"

if ($condition2) {
    $parameters = $parameters + " /v"

.\MyCommand.exe $parameters

The problem is that I'm not really passing a single string parameter to MyCommand.exe, but rather the string contains multiple parameters that should be passed in.

share|improve this question
up vote 1 down vote accepted

use Invoke-Expression

$RunQuery=.\MyCommand.exe + ' ' + $parameters
iex $RunQuery

real test:

$VerLDAP='dsquery * "cn=schema,cn=configuration,'+([ADSI]"LDAP://rootDSE").rootDomainNamingContext+'" -scope base -attr objectVersion'
iex $VerLDAP
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.