I would use the built in environment variables, but am running in a SCCM OSD 
task sequence and prefer the TS variables over environment variables.

Two solutions that would work, thanks again guys.

Daniel Ratliff

From: [email protected] [mailto:[email protected]] On 
Behalf Of Eric Laizure
Sent: Tuesday, June 6, 2017 12:44 PM
To: [email protected]
Subject: RE: [powershell] RE: PowerShell.exe from cmd - WMI filter quotes

Devin beat me to it. ☺ Also, you may want to change %Hostname% to 
$($Env:COMPUTERNAME), otherwise your file will literally be 
%Hostname%_printers.csv.

Eric Laizure

From: [email protected]<mailto:[email protected]> 
[mailto:[email protected]] On Behalf Of Devin Rich
Sent: Tuesday, June 6, 2017 9:34 AM
To: [email protected]<mailto:[email protected]>
Subject: Re: [powershell] RE: PowerShell.exe from cmd - WMI filter quotes

I think Eric's works, you just missed the opening ' before Portname. :)

I like Where-Object, but if I need server side performance, then I will use 
-Filter (typically with large AD domains).

Thanks,
Devin Rich
Systems Administrator

On Tue, Jun 6, 2017 at 10:10 AM, Daniel Ratliff 
<[email protected]<mailto:[email protected]>> wrote:
It doesn’t like that one. Trying Devin’s suggestion now.

[cid:[email protected]]

Daniel Ratliff

From: [email protected]<mailto:[email protected]> 
[mailto:[email protected]<mailto:[email protected]>] 
On Behalf Of Eric Laizure
Sent: Tuesday, June 6, 2017 11:53 AM
To: [email protected]<mailto:[email protected]>
Subject: [powershell] RE: PowerShell.exe from cmd - WMI filter quotes

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]> 
[mailto:[email protected]] On Behalf Of Daniel Ratliff
Sent: Tuesday, June 6, 2017 8:12 AM
To: [email protected]<mailto:[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.



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.



The information contained in this message is privileged, confidential, and 
protected from disclosure. If you are not the intended recipient, you are 
hereby notified that any review, printing, dissemination, distribution, copying 
or other use of this communication is strictly prohibited. If you have received 
this communication in error, please notify us immediately by replying to the 
message and deleting it from your computer.


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.

Reply via email to