Disk Unique ID

Hi, 

 

Is there is any way i can get the disk unique ID as shown below with powershell & WMI

 

DISKPART> detail disk

 

XXXXXXXXX SCSI Disk Device

Disk ID: {XXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}

Type   : SATA

  • Try:

    $disks = gwmi Win32_Volume -filter "drivetype=3"

    Then look at the DeviceID property.

  • Thanks for your reply but deviceID value is not matching with the uniqueid value provided by diskpart,

    Please see below for your reference:

     

    PS C:\Users\atayal12> gwmi Win32_Volume -filter "drivetype=3" | Select DeviceID

     

    DeviceID

    --------

    \\?\Volume{c0d4362f-24b4-49d1-a5df-9298f56b319a}\

    \\?\Volume{3264d867-78c4-42f8-bf70-3f84da0858ec}\

     

    DISKPART> detail disk

     

    ST500LM0 21-1KJ152 SCSI Disk Device

    Disk ID: {47163BDC-8D5E-4415-AE2F-6ED7398B0C89}

    Type   : SATA

    Status : Online

    Path   : 0

    Target : 0

    LUN ID : 0

    Location Path : PCIROOT(0)#ATA(C00T00L00)3f84da0858ec}\

    PS: UNIQUEID - Displays or sets the GUID partition table (GPT) identifier or master boot record (MBR) signature of a disk.

     

  • Oh, that thing. I only know one way to get it, but it ain't pretty. See if this is it:

     

    foreach ($disk in (gwmi win32_diskdrive)) {
       [convert]::tostring($disk.signature, 16)
    }

     

    There are probably other ways to do that, but I don't know what they are.

  • Thanks again for your response but not getting the desired with this approach as well.

    i can see unique id is part of this class MSFT_Disk, can you help me in accessing this class properties on a window 7 machine.

  • I don't know enough about how DISKPART puts together the Disk ID to go any further with WMI. If you really need that ID number, why don't you just run it through Powershell? First set up a command file for DISKPART:

     

    select disk 0
    detail disk
    exit

     

    Save it with a name like "diskpart_cmds.txt" and run it through Powershell:

     

    foreach ($line in (diskpart /S diskpart_cmds.txt)) {
       if ($line -match "^Disk ID: ") { ($line -split ": ")[1]; }
    }

    That should give you the ID.

  • In this way we are currently doing but was luking for a way in which i can get the same details via WMI class.

    Thanks again for your help.

  • Use Win32_DiskDrive.
    PS > Get-WmiObject Win32_DiskDrive | sort Index | ft Index,DeviceID,@{l='Signature';e={"{0:X}" -f $_.Signature}},Model -a
    
    Index DeviceID           Signature Model
    ----- --------           --------- -----
        0 \\.\PHYSICALDRIVE0 1A67EB78  WDC WD6400AAKS-22A7B0 ATA Device
        1 \\.\PHYSICALDRIVE1           ST4000DM000-1F2168 ATA Device
        2 \\.\PHYSICALDRIVE2 0         IOI CF/MicroDrive USB Device
        3 \\.\PHYSICALDRIVE3 0         IOI SM/xD-Picture USB Device
        4 \\.\PHYSICALDRIVE4 0         IOI SD/MMC USB Device
        5 \\.\PHYSICALDRIVE5 0         IOI MS/MsPro USB Device
        6 \\.\PHYSICALDRIVE6 A4B57300  Seagate FreeAgentDesktop USB Device
        7 \\.\PHYSICALDRIVE7           Seagate Desktop USB Device
        8 \\.\PHYSICALDRIVE8 511F7654  WD My Passport 0820 USB Device
    
    
  • Thanks Sean for your response but still not getting the desired results.

  • Win32_DiskDrive returns the Signature as a decimal value. You have to convert it to hex to match the value returned by the diskpart command.

  • Yeah, that's the same stuff I was posting, but it isn't giving him what he's looking for. I'm working on the theory that they may be doing something different with the Disk ID through DiskPart. I've never seen GUIDs in the wild like he's showing in the first few posts, but I don't know that much about DiskPart.

  • After doing a bit more research to this, i was able to find this information

    Signature property of WMI class Win32_DiskDrive shows correctly disk signature for MBR disks and same matches with Diskpart output as well.

    However for GPT disks this field is null. Is there any other new WMI class to represent GPT disks?

     

    Thanks.