Script for finding out disk number

1

I have an external hard disk with two partitions. The first one is an UDF partition and the second partition is a Veracrypt partition. Now I want to use a batch script to load the Veracrypt partition using Veracrypt Command Line. But I cannot find the GUID of the partition. Mountvol does not list the partition. The only approach is to use the Device\HardDisk [number]/Partition [number] approach. Now I can get the correct harddisk and partition number using Diskpart. But I cannot implement it into a script. If anyone could help me out in this, it'd be a great help.

Mycroft Holmes

Posted 2015-05-09T11:07:14.487

Reputation: 35

1What operating system are you using? I'm guessing Windows but I;m not sure. If it is Windows, which version? – terdon – 2015-05-09T12:10:43.597

It is Windows 7 32bit Professional Edition – Mycroft Holmes – 2015-05-09T23:41:06.757

Answers

0

I figured it out myself. I did it in Powershell though. Had to learn Powershell from the scratch for this.

$diskdrv = Get-WmiObject -Class Win32_DiskDrive -Filter "Caption='WD Elements 1078 USB Device'"
if ($diskdrv.SerialNumber.Contains("WXS1E94D125E"))
{
    $index = $diskdrv.Index
    Write-Host Hard Disk found at Index $Index
    $volume = "\Device\Harddisk"+ $index + "\Partition2"
    write-host Volume located at $volume
    &"I:\Applications\VeraCrypt Portable\veracrypt.exe" /v $volume /lS /e /b  /q
 }

Mycroft Holmes

Posted 2015-05-09T11:07:14.487

Reputation: 35