4

I need to create a T volume, T is created, but I also need a new U volume if the disk is a ssd, how i can do it ? What is the batch command to know if I'm a SSD ?

[...]
set /a VOL_SIZE= %MINSIZE_MB% /2
set VOL_TYPE=simple
if %NDISK% GTR 1 set VOL_TYPE=stripe

echo create volume %VOL_TYPE% size=%VOL_SIZE% disk=%DISKLIST%   >>%CMD_FILE%
echo Format fs=NTFS quick                                       >>%CMD_FILE%
echo assign letter=T                                            >>%CMD_FILE%


::if I'm not a SSD goto :noSSD

echo create volume %VOL_TYPE% disk=%DISKLIST%                   >>%CMD_FILE%
echo Format fs=NTFS quick                                       >>%CMD_FILE%
echo assign letter=U                                            >>%CMD_FILE%

:noSSD
[...]

best regard.

Awesome JSF
  • 85
  • 1
  • 8

2 Answers2

7

As an alternative to using , you could also try via .

Open a Command Prompt window, paste the following line, and press ENTER

For /F Tokens^=6Delims^=^" %G In ('^""%SystemRoot%\System32\wbem\WMIC.exe" /NameSpace:\\root\Microsoft\Windows\Storage Path MSFT_PhysicalDisk Where "MediaType='4' And SpindleSpeed='0'" Get Model /Format:MOF 2^>NUL^"')Do @Echo %G is an SSD

This accesses the same information as PowerShell's Get-PhysicalDisk. It first checks the MediaType property. There are three possible values returned for that property, 0 (Unspecified); 3 (HDD); and 4 (SSD). For additional safety, I check that there is a spindle speed of 0 as there are no moving parts in an SSD, and return any model name which passes both checks.

Compo
  • 36,585
  • 5
  • 27
  • 39
  • you should have the accept, the user accepted without testing. They are using windows 7 or server 2008R2, and this method, or using Diskpart in cmd are the obly methods which will work. – Ben Personick Sep 24 '20 at 15:01
  • Does this require Windows 10? on my Windows 7 Enterprise machine it says `Invalid class`… – aschipfl Sep 24 '20 at 15:55
  • 1
    I was unable to test this at the time of posting @aschipfl. I've since managed to try it on three different systems. On Windows Vista Home Premium it did not work, outputting the error `Invalid Namespace`. On a Windows 7 Home Premium unit, it also failed with exactly the same message. It did work exactly as advertised on Windows 10 Professional unit though, but I cannot say for sure whether the Operating System version is the defining reason, or the edition, and as your Windows 7 edition outputs a different error message, I wouldn't want to take a guess. – Compo Sep 24 '20 at 19:43
  • Thanks for your tests! At first I also received the same error `Invalid namespace`, seems I copied the wrong message in my previous comment after removing the `/NameSpace` part for another test. On my Windows 10 notebook it works… – aschipfl Sep 24 '20 at 19:51
3

In cmd you can type following command which invokes PowerShell and passes it command which will return "SSD" if disk is of that type:

powershell.exe "(get-physicaldisk).MediaType"

Per phuclv's advice, simplest way to use return value of this command in batch file would be:

powershell.exe "exit ((get-physicaldisk).MediaType) -ne 'SSD'" && echo SSD

Statement explanation, when SSD is present:

  • ((get-physicaldisk).MediaType) - evaluates to 'SSD'
  • 'SSD' -ne SSD' - evaluates to False (-ne is not-equal operator)
  • exit with logical false (False) - makes PowerShell exit without setting CMD's %ERRORLEVEL% to non-zero
  • && - is CMD operator that executes second command when first command is successful (when %ERRORLEVEL% is zero)
Ivan Golović
  • 8,732
  • 3
  • 25
  • 31
  • Thank you, but I'm on windows 7, the command doesn't work ;( – Awesome JSF Sep 24 '20 at 09:56
  • No problem, installing PowerShell on Windows 7 is not an option for you - you have to do it without PowerShell? – Ivan Golović Sep 24 '20 at 10:00
  • I can use powerShell, but it don't recognize the command. – Awesome JSF Sep 24 '20 at 10:09
  • If version of PowerShell is older perhaps you can update it, I read it can be updated n Windows 7 to PowerShell 5. If that doesn't help there are some additional tips on https://social.technet.microsoft.com/Forums/ie/en-US/6816a942-54e3-4796-adb4-1bce121bfac7/getphysicaldisk-the-term-getphysicaldisk-is-not-recognized-as-the-name-of-a-cmdlet?forum=winserverpowershell - they rely on parsing string "SSD" from model name, but not all models have that string in model name although they are SSD – Ivan Golović Sep 24 '20 at 10:21
  • 2
    you don't even need to store the result to a temp file, the output can be read using `for /F`. But the best method is just return the compare result directly from powershell: `powershell.exe "exit ((get-physicaldisk).MediaType) -ne 'SSD'" && echo SSD` – phuclv Sep 24 '20 at 13:04
  • This functionality doesn't work on windows 7/2008R2 you need at least 2012 R2 for this command to work, its a limitation of the OS, not a PowerShell version issue. – Ben Personick Sep 24 '20 at 14:55
  • You can get this info from Diskpart and / or WMIc through CMD wirh some fanageling – Ben Personick Sep 24 '20 at 14:56