Try this. Since this is being executed from Batch or just the command line, you
can't use but 1 double quote. You have to split it out into 2 single quote
marks. At least, that's how I've had to do something similar to this.
powershell.exe -executionpolicy bypass -command "& {Get-WmiObject win32_printer
-Filter 'PortName LIKE ''%.%.%.%''' | select Name, PortName | ConvertTo-Csv
-NoTypeInformation | out-file c:\temp\%Hostname%_printers.csv}"
Eric Laizure
From: [email protected] [mailto:[email protected]] On
Behalf Of Daniel Ratliff
Sent: Tuesday, June 6, 2017 8:12 AM
To: [email protected]
Subject: [powershell] PowerShell.exe from cmd - WMI filter quotes
Any ideas on how to get around this? I have played around with the backtick,
double quotes, single quotes, and cannot seem to find a working syntax. It is
failing on the WMI filter.
powershell.exe -executionpolicy bypass -command "& {Get-WmiObject win32_printer
-Filter "PortName LIKE '%.%.%.%'" | select Name, PortName | ConvertTo-Csv
-NoTypeInformation | out-file c:\temp\%Hostname%_printers.csv}"
[cid:[email protected]]
Daniel Ratliff
The information transmitted is intended only for the person or entity to which
it is addressed
and may contain CONFIDENTIAL material. If you receive this material/information
in error,
please contact the sender and delete or destroy the material/information.