Search code examples
batch-filewmic

wmic /failfast does nothing


    for /f "tokens=*" %%a in (ip.txt) do (


     wmic /FAILFAST:ON /node:%%a /user: /password: computersystem get Name, domain, Manufacturer, Model, NumberofProcessors, PrimaryOwnerName,Username, Roles, totalphysicalmemory /format:list
     wmic /FAILFAST:ON /node:%%a /user: /password: cpu get Name, Caption, MaxClockSpeed, DeviceID, status /format:list
     wmic /FAILFAST:ON /node:%%a /user: /password: path Win32_VideoController get Name, status, DeviceID /format:list
     wmic /FAILFAST:ON /node:%%a /user: /password: os get Version, Caption, CountryCode, CSName, Description, InstallDate, SerialNumber, ServicePackMajorVersion, WindowsDirectory /format:list
     wmic /FAILFAST:ON /node:%%a /user: /password: csproduct get identifyingnumber /format:list


    ) >%%a.txt

This is my code and it works like it should do, but the /FAILFAST:ON it does skip to next if you wait 10-20 sec, I need it to go faster to scan large systems, anybody got any ideas?

Could I use an if command that pings with 1 packet and goes to next if no response ?

thanks to JosefZ:

    for /f "tokens=*" %%a in (ip.txt) do (
  set "_ready="
  for /F %%G in ('ping -4 -n 1 %%a^|find "TTL="') do set "_ready=%%G"
  if defined _ready (
      rem your `WMIC /FAILFAST:OFF /node:%%a …` 
         wmic /node:%%a /user: /password: computersystem get Name, domain, Manufacturer, Model, NumberofProcessors, PrimaryOwnerName,Username, Roles, totalphysicalmemory /format:list
         wmic /node:%%a /user: /password: cpu get Name, Caption, MaxClockSpeed, DeviceID, status /format:list
         wmic /node:%%a /user: /password: path Win32_VideoController get Name, status, DeviceID /format:list
         wmic /node:%%a /user: /password: os get Version, Caption, CountryCode, CSName, Description, InstallDate, SerialNumber, ServicePackMajorVersion, WindowsDirectory /format:list
         wmic /node:%%a /user: /password: csproduct get identifyingnumber /format:list

  )>"%%a.txt"
)

Solution

  • Read about /FAILFAST switch:

    Whether or not the /NODE computers are checked before trying to execute the WMIC commands against them. When FAILFAST is ON, WMIC pings the computers in the /NODE switch before sending WMIC commands to them. If they do not respond to the ping, the WMIC commands are not executed for them.

    One log file for each server:

    for /f "tokens=*" %%a in (ip.txt) do (
      set "_ready="
      for /F %%G in ('ping -4 -n 1 %%a^|find "TTL="') do set "_ready=%%G"
      if defined _ready (
          rem your `WMIC /FAILFAST:OFF /node:%%a …` commands here
      )>"%%a.txt"
    )
    

    or the only log file for all servers:

    for /f "tokens=*" %%a in (ip.txt) do (
      set "_ready="
      for /F %%G in ('ping -4 -n 1 %%a^|find "TTL="') do set "_ready=%%G"
      if defined _ready (
          rem your `WMIC /FAILFAST:OFF /node:%%a …` commands here
      )
    )>"logservers.txt"