Author Posts

April 28, 2015 at 8:14 am

I'm trying to execute a command against another application(PTC Integrity) and am having trouble getting it formatted correctly within PowerShell.

I am able to add the –% parm to the command and get it to work by hard coding the search value(in this example – "abc (def)" ) –

im issues --hostname=$host --user=$User --port=$Port --% --queryDefinition='((field[FRED] contains "abc (def)") and (field["Type"] = "Group Definition"))' --fields="ID"

However I need to pass that search string as a variable to the command. Something like this –

$Search = "abc (def)"
im issues --hostname=$host --user=$User --port=$Port --queryDefinition='((field[FRED] contains $Search) and (field["Type"] = "Group Definition"))' --fields="ID"

The Integrity app is returning this error with that query –

*** The query and queryDefinition options are incompatible with an issue selection.

Essentially the command isn't getting parsed correctly, and it believes I'm trying to pass an incorrect value with my queryDefinition statement.

I've tried every combination of quotations and escapes I can think of here.

Any thoughts as to how I should be formatting this properly?


April 28, 2015 at 12:44 pm

I found the resolution here – [url][/url]

The variable needs to double escaped inside the string, once for Powershell using the backtick(`), and once for the parser using a backslash(\). So the variable ends up looking like this – \`"$Search\`"

And the full command then look slike this –

$Search = "abc (def)"
im issues - -hostname=$host - -user=$User - -port=$Port - -queryDefinition="((field[FRED] contains \`"$Search\`") and (field[Type] = Group Definition))" - -fields="ID"