0

I am trying to get Model and Size of all local disks.
I want to output on one line for each disk.
Example: Model Samsung Size 500GB

@echo off
for /f "tokens=2 delims==" %%d in ('wmic diskdrive get Model,Size /value') do (
    set Model=%%d
set Size=%%d
)
echo Model %Model% Size %Size%
pause

But nothing.

rene
  • 41,474
  • 78
  • 114
  • 152
Orion8
  • 41
  • 9
  • Simply omit `/Value` to get one line per disk with an initial header, but remember wmic output is UTF16LE encoded. –  Jun 07 '19 at 11:35

2 Answers2

1

As model descriptions may contain spaces, you need to format the output as csv, so the output is delimited by commas (I hope there aren't model descriptions that contain commas - I didn't see one so far).

Without /value each disk is listed in one line (Node,Model,Size), so you need tokens=2,3. Add a skip=2 to remove the header line and add your fixed strings to the final output:

for /f "skip=2 tokens=2,3 delims=," %%a in ('"wmic diskdrive get Model,Size /format:csv"') do @echo Model %%a Size %%b
Stephan
  • 53,940
  • 10
  • 58
  • 91
  • The code working fine. Would you please convert the bytes of size to Gigabte size ?. – Orion8 Jun 07 '19 at 22:43
  • We will happily help you with your code when you have problems, but please don't ask us to write code for you for free. – Stephan Jun 08 '19 at 12:44
0

Here is one way to do it on all current day, supported Windows machines. The stated goal is "one line." If you want model and size in separate variables, there is more to do.

powershell -NoLogo -NoProfile -Command ^
    "Get-CimInstance -ClassName CIM_DiskDrive |" ^
    "ForEach-Object { 'Model {0} Size {1}' -f @($_.Model, $_.size) }"
lit
  • 14,456
  • 10
  • 65
  • 119