title: How to get the Percentage of memory utilization using WMIC in batch script?
body: <p>I am not getting the result for Percentage of memory utilization in batch script using only W MIC. I am getting only total memory and free memory in bytes.</p>
  
  <p>So how to a get those in Megabytes and how to calculate percentage of memory utilization?</p>
  
  <p>Code :- </p>
  
  <pre><code>@echo off
  setlocal enabledelayedexpansion
  
  set Times=0
  for /f "skip=1" %%p in ('wmic cpu get loadpercentage') do (
      set Cpusage!Times!=%%p
      set /A Times+=1
  )
  
  echo CPU Percentage = %Cpusage0%%%
  
  set Times=0
  for /f "skip=1" %%p in ('wmic ComputerSystem get TotalPhysicalMemory') do (
      set totalMem!Times!=%%p
      set /A Times+=1
  )
  
  set Times=0
  for /f "skip=1" %%p in ('wmic OS get FreePhysicalMemory') do (
      set availableMem!Times!=%%p
      set /A Times+=1
  )
  
  set Times=0
  for /f "skip=1" %%p in ('wmic OS get FreePhysicalMemory ^|findstr physical') do (
      set /a UsedMem= totalMem - availableMem
      set usedMem!Times!=%%p
      set /A Times+=1
  )
  set /a usedpercent=(usedMem*100)/totalMem
  
  echo Free MEMORY = %availableMem0% Bytes
  echo Total MEMORY = %totalMem0% Bytes
  echo Used MEMORY = %UsedMem0% Bytes
  echo Memory Utilization = %usedpercent0%%%
  
  pause
  </code></pre>