2

This runs fine from the PS command prompt:

Get-WmiObject Win32_Share -computer "Server" -filter "Name = 'ShareName'"

When added to Ruby I can get this to execute (because it doesn't need quotes):

powershell (Get-WmiObject Win32_Share -computer "Server")

but not with the filter argument (needs quotes):

powershell (Get-WmiObject Win32_Share -computer "Server" **-filter "Name = 'ShareName'"**)

The output of the error does not show the double quotes. I tried everything I know to escape them and nothing works.

tried (... -filter \"Name = 'ShareName'\")
tried %x{} instead of ``
tried single quotes

AndrewC
  • 32,300
  • 7
  • 79
  • 115
Dean8088
  • 21
  • 3
  • I don't think I see any valid ruby code here. Could you post your actual ruby code and tell us what you expect it to do versus what it actually does? – David Grayson Feb 05 '13 at 21:42
  • It's executing from a Ruby (well, rake) script. I included Ruby in the tag since it or PowerShell seem to be messing with the quotes or most likely I haven't found the correct sequence of quotes that makes it work. So, the Ruby is `` and %x[] that contains the PS command. – Dean8088 Feb 05 '13 at 22:02

1 Answers1

0

In powershell, the value between a double quote string is interpreted, such as an object $HelloWorld containing the string "Hello world". Powershell handles $HelloWorld the same way it handles "$helloWorld". However if you type '$HelloWorld' it will interpret it literally and print the object name, $HelloWorld as a string.

PS> $HelloWorld = "Hello World"
PS> $helloworld
Hello World
PS> "$helloworld"
Hello World
PS> '$helloworld'
$helloworld

try something like this...

PS> "'$helloworld'"
'Hello World'
Christopher Douglas
  • 1,519
  • 2
  • 9
  • 16