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?
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.