0

I am trying to run below powershell script and passing $project_name in --project parameter but that is not accepting and not referring to variable. How would i use that ?

$project_name = "webapp_deploy1"

$command = "C:\Program Files\Octopus Deploy\Octopus\Octopus.Migrator.exe"

$param = @('partial-export','--project=$project_name','--password=deploy1','--directory=D:\Export Project','--ignore-history','--ignore-deployments','--ignore-tenants','--ignore-certificates','--ignore-machines')

& $command $param 
3
  • 1) Please use code formatting (indent 4 spaces). 2) How do you know your command line is not working? Do you get an error? (Remember: We can't see your screen.) Commented Aug 8, 2019 at 18:22
  • I am getting below error Octopus.Migrator.exe : The following projects were not found: '$project_name' At line:7 char:1 + & $command $param + ~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (The following p...'$project_name':String) [], RemoteExceptio n + FullyQualifiedErrorId : NativeCommandError Commented Aug 8, 2019 at 18:26
  • For an overview of string literals and string expansion in PowerShell, see the bottom section of this answer. Commented Aug 8, 2019 at 20:21

2 Answers 2

1

Don't use single quotes if you want variables to be expanded. use "

"--project=$project_name"
Sign up to request clarification or add additional context in comments.

11 Comments

The " characters shouldn't be necessary.
@Bill_Stewart Actually, I don't think powershell normally interprets variables when it looks like a parameter, unless there's a colon.
Not sure why you say that, but it's not correct. I just tested again with my showargs.exe utility (it outputs the actual command line that PowerShell passes to it), and --param=$arg (where $arg contains a string) works just fine. If $arg contains spaces, PowerShell quotes the argument.
Correct, @Bill_Stewart, but do note that the OP defines the parameter as a string as part of an array, where quoting is indeed needed.
@js2010: The problem only occurs with a single leading - followed by a letter; Try Write-Output --project-name=$HOME, and you'll see that it works fine.
|
0

I don't suppose you could run it this way.

$project_name = 'webapp_deploy1'
& "C:\Program Files\Octopus Deploy\Octopus\Octopus.Migrator.exe" partial_export --project="$project_name" --password=deploy1 --directory='D:\Export Project' --ignore-history --ignore-deployments --ignore-tenants --ignore-certificates --ignore-machines

3 Comments

I am able to run this and it works as well but i want to pass variable in --project=$project_name instead of providing actual project name (Web_deploy1)
Ok, I changed it.
This works $project_name = "webapp_deploy1" & "C:\Program Files\Octopus Deploy\Octopus\Octopus.Migrator.exe" partial-export --project="$project_name" --password=deploy1 --directory='D:\Export Project' --ignore-history --ignore-deployments --ignore-tenants --ignore-certificates --ignore-machines

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.