0

I have a simple Powershell script that I execute during an Octopus Deploy installation. This line works fine:

& $exe install --autostart

I runs an application identified by $exe variable with command line arguments "install --autostart".

Now I need to expand command line arguments with a value evaluated from a variable:

& $exe install --autostart -servicename=$serviceName

"$serviceName" is the variable that gets its value during the script execution. Whatever I do it's passed to the line above by variable name, not the value, e.g. it's passed as "$serviceName". I tried single and double quotes, nothing helps. As long it's a command invocation (triggered by the "&" symbol in the beginnging of the line), the rest of the line is interpreted verbatim, no variable substitions.

I used last couple of hours trying to figure this out and this is driving me mad. Any tips are appreciated.

1 Answer 1

1

I just did some testing on my side and it looks like if you'd like the variable passed in to the command to be evaluated as a variable it needs whitespace on both sides. So you would want to define your variable as $serviceName = "-servicename=*name*" or if that is not possible then create a new variable just before running the command

$tmpServicename = "-servicename=$($serviceName)"
& $exe install --autostart $tmpServiceName
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, it helped!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.