Display dollar sign as wmi query filter
I am trying to request a service named AOS60 $ 01
get-service 'AOS60$01'
works fine, but when I use:
get-wmiobject win32_service -filter "Name='AOS60$01'"
returns nothing. I assume it thinks $ 01 is a variable and replaces it with an empty string, so it doesn't work. Tried running the dollar sign with a backslash, but it didn't work. How can I avoid this?
source to share
When you use the double quotes "$ test", you get the value of the variable. When you use the single quote "$ test", you get it as it is.
Since you are using single quotes within a string, either of two ways of doing this is fine:
... -filter "Name='AOS60`$01'"
The reverse side of `is used for this.
Alternatively, you can use single quotes and escape them:
... -filter 'Name=''AOS60$01'''
To avoid a single quote, put another quote in front of it.
source to share