Michael Gabbay
Michael Gabbay

Reputation: 465

Run powershell command with quote marks via cmd

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

Upvotes: 1

Views: 1092

Answers (1)

iRon
iRon

Reputation: 23663

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''')"

Upvotes: 2

Related Questions