Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.