Reputation: 13
I'm trying to use various WMI queries to gather data needed for daily reports on some of my servers. The only piece of my script that fails is the final step, which queries for the status of certain services. The query works fine when I type it manually into the command line, but it fails when I dump it into a batch script. I'm limited to using plain old Windows Command Line, so no Power Shell or vb. Here's the command:
wmic /OUTPUT:"%HOMEDRIVE%%HOMEPATH%\Desktop\AutoDMR\DMRAuto_3.txt" service where "name like 'MPCX%' or name like 'nm%' or name like 'nb%' or name like 'ssacpha%' or name like 'EMC%'" get name,state,status /FORMAT:htable
Thanks!
Upvotes: 1
Views: 1576
Reputation: 130819
All percents in a batch script must be doubled. For example 'EMC%'
becomes 'EMC%%'
Also, if you attempt to run command within a FOR /F IN() clause, then the commas in the GET clause must be escaped as ^,
.
for /f ... in ('wmic ... get name^,state^,status ...') do ...
Upvotes: 2