0

When I execute the following script block, I get an error:

powershell_script 'uninstall_something' do
   code 'wmic /failfast:on product where "name like 'Something Enterprise(64-bit)'" call uninstall /nointeractive'
   guard_interpreter :powershell_script
end

FATAL: SyntaxError: .\check.rb:6: syntax error, unexpected tCONSTANT, expecting keyword_end
...roduct where "name like 'Something Enterprise(64-bit)'" call un...
                                     ^
.\check.rb:6: syntax error, unexpected tSTRING_BEG, expecting keyword_end
...ike 'Something Enterprise(64-bit)'" call uninstall /nointeracti...
                                     ^

I have tried escaping the spaces but I still get the error. If I execute the same PowerShell command in PowerShell, I don't get any error. What am I missing?

2
  • You have to escape your interior single quotes. Your string right now is code 'wmic /failfast:on product where "name like ' and everything after that is a syntax error. Commented Mar 21, 2018 at 20:54
  • @Joe If I do that, the script succeeds without any errors but it fails to do what its supposed to do, i.e, uninstall Something Enterprise. code 'wmic /failfast:on product where "name like \'Something Enterprise(64-bit)\'" call uninstall /nointeractive' Commented Mar 21, 2018 at 21:13

1 Answer 1

1

You can use %q[...] if both other quotes are already in use:

code %q[wmic /failfast:on product where "name like 'Something Enterprise(64-bit)'" call uninstall /nointeractive]
Sign up to request clarification or add additional context in comments.

2 Comments

If I do that, the script succeeds without any errors but it fails to do what its supposed to do, i.e, uninstall Something Enterprise
That's a problem, I'm sure, but it's also another question. Stack Overflow tries to keep things focused on one issue at a time. It helps crowd out these questions with lots of other confusion.

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.