1

I need to run a powershell command via CMD

my command is

(Get-WmiObject -Class win32_pnpEntity -Filter 'Name like "ACPI Thermal Zone"')
[1].GetDeviceProperties().DeviceProperties  |
Select-Object -Property keyName, data

and i get successful result: enter image description here

However, when i try to run the same command with cmd, I getting exception in the query execution. it looks like something with the quote marks in the command.

Cmd command

powershell -command "(Get-WmiObject -Class win32_pnpEntity -Filter 'Name like "ACPI Thermal 
Zone"')"

Cmd error enter image description here

Please help, what do i miss?

Edit

I tried double quotes and escape char with no luck enter image description here

2
  • tried, still didn't get it work Commented Jul 15, 2021 at 9:53
  • 1
    Isn't ` the escape character for PS? Commented Jul 15, 2021 at 11:54

1 Answer 1

2

You might resolve this at a CMD level by escaping the double quotes with a backslash (\"):

PowerShell -command "Get-WmiObject -Class win32_pnpEntity -Filter 'Name like \"ACPI Thermal Zone\"'"

... or as WMI queries also accepts single quotes for names in filters.
You might also simply avoid the double quotes in the WMI query and resolve this with (escaped) single quotes ('') at a PowerShell level:

PowerShell -command "(Get-WmiObject -Class win32_pnpEntity -Filter 'Name like ''ACPI Thermal Zone''')"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.