Get-WmiObject -Class win32_logicaldisk -Filter \'DeviceID=\"C:\"\'
does what I want,
$var=\"C:\"
Get-WmiObject -Class win32_logical
When you start a string literal with '
(single-quotes), you're creating a verbatim string - that is, every character inside the string is interpreted literally and variable references and expressions won't expand!
Use "
if you want the variable to be expanded:
$var = 'C:'
Get-WmiObject -Class win32_logicaldisk -Filter "DeviceID='$var'"
If your variable name has weird characters, or is followed by a word character, you can qualify the variable name with curly brackets {}
immediately after the $
:
$var = 'C:'
Get-WmiObject -Class win32_logicaldisk -Filter "DeviceID='${var}'"