Script Batch Win11

Discussion in 'Windows 11' started by MrNico98, Feb 2, 2024.

  1. MrNico98

    MrNico98 MDL Junior Member

    May 9, 2023
    52
    6
    0
    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?
     

    Attached Files:

    • disk.png
      disk.png
      File size:
      125.1 KB
      Views:
      92
  2. 12 lb Turkey

    12 lb Turkey MDL Junior Member

    Nov 24, 2022
    86
    48
    0
    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
     
  3. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,781
    5,277
    120
    #3 Dark Dinosaur, Feb 3, 2024
    Last edited: Feb 3, 2024
    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
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. haris_mdlf69

    haris_mdlf69 MDL Senior Member

    Oct 23, 2018
    436
    681
    10
    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!:p
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...