5641

Escaping dollar sign in a wmi query filter

Question:

I'm trying to query a service named AOS60$01

get-service 'AOS60$01' works fine but when I use:

get-wmiobject win32_service -filter "Name='AOS60$01'" it does not return anything. I assume it thinks $01 is a variable and replaces it with an empty string that's why it is not working. Tried escaping the dollar sign with a backslash but it did not work. How do I escape it?

Answer1:

Try it with a backtick ` :

get-wmiobject win32_service -filter "Name='AOS60`$01'"

Answer2:

When you use double quotes "$test" you get the value of the variable. When you use single quotes '$test' you get it as-is.

As you are using single quotes inside the string, either of the two ways of doing it are appropriate:

... -filter "Name='AOS60`$01'"

This uses a backtick ` to escape it.

Alternatively you can use single quotes and escape them instead:

... -filter 'Name=''AOS60$01'''

To escape a single quote, put another single quote in front of it.

Recommend

  • Dynamics AX 2012 RegConfig does not work
  • looking for cleaner code when embedding razor calls in text
  • How to shorten this expression using regex
  • Add a div to replace Video after Video Plays Through
  • Sql indexes vs full table scan
  • How to name a 'group' check box in Adobe Reader when wanting to fill form by FDF / XFDF
  • Creating a setup.exe in InstallShield in Visual Studio
  • Thread synchronization with syncwarp
  • What does “t” refer to in this SQL?
  • cordova is not defined - cordova.js has already been loaded :: Ionic
  • CERN ROOT exporting data to plain text
  • jQuery: add elements until a particular height is reached
  • Android changing fragment order inside FragmentPagerAdapter
  • Combining two different ActiveRecord collections into one
  • Django simple Captcha “No module named fields” error
  • How to use carriage return with multiple line?
  • Jackson Parser: ignore deserializing for type mismatch
  • How to use remove-erase idiom for removing empty vectors in a vector?
  • Why does access(2) check for real and not effective UID?
  • Repeat a vertical line on every page in Report Builder / SSRS
  • Why is an OPTIONS request sent to the server?
  • Spring security and special characters
  • Regex thinks I'm nesting, but I'm not
  • Weird JavaScript statement, what does it mean?
  • How do you troubleshoot character encoding problems?
  • AT Commands to Send SMS not working in Windows 8.1
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • How to format a variable of double type
  • retrieve vertices with no linked edge in arangodb
  • A cron job substitute?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Linking SubReports Without LinkChild/LinkMaster
  • apache spark aggregate function using min value
  • Django query for large number of relationships
  • Sorting a 2D array using the second column C++
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How to Embed XSL into XML
  • How can I use `wmic` in a Windows PE script?
  • Python/Django TangoWithDjango Models and Databases
  • How to push additional view controllers onto NavigationController but keep the TabBar?