I need this piece of code to find whether the disk is SSD or HDD. If only one disk is used it's fine, otherwise it works like hell. Is there a way to tell it to only inspect the system disk?
MediaType for the System Disk (don't assume it's always C:\): Code: powershell "(Get-PhysicalDisk -DeviceNumber (Get-Partition -DriveLetter (Get-WmiObject Win32_OperatingSystem).SystemDrive.TrimEnd(':')).DiskNumber).MediaType" SSD (Get-WmiObject Win32_OperatingSystem).SystemDrive.TrimEnd(':') -> C (Get-Partition -DriveLetter C).DiskNumber -> Disk 0 (Get-PhysicalDisk -DeviceNumber 0).MediaType -> SSD
this could be fun. also add check for PowerShell command failure if regex fail `"^True$ ^False$"` ... command fail .. . Code: @cls @echo off echo: for /f "usebackq tokens=*" %%# in (`powershell -nop -c "Get-Partition | ? DriveLetter -eq $env:SystemDrive.Substring(0,1) | Get-Disk | Get-PhysicalDisk | %% { return ($_.MediaType -eq 'SSD') }"`) do ( (echo %%#|>nul findstr /r /i "^True$ ^False$") && ( if /i %%# EQU True ( echo System drive *is* SSD ) if /i %%# EQU False ( echo System drive *is NOT* SSD ) ) || ( echo powershell command error )) echo: pause
From where I can learn this sorcery my friend? I couldn't think of a more fun and dynamic companion to embark on this journey with than you!