Eu também fiz um script do Powershell para fazer o mesmo trabalho. O Powershell faz um trabalho melhor que o script em lote.
$driveI = Get-WmiObject -Class win32_volume -Filter "DriveLetter='I:'"
if ($driveI -eq $null) {
write-host "I: is free..."
} elseif ($driveI.DeviceID.Contains("7899c0f7-f556-11e4-9cf2-7071bc4ab2b5") -And "$drive.SerialNumber = '-1675536360'") {
write-host "I: is already assigned to the required disk..."
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
exit
} else {
write-host "I: is occupied..."
foreach ( $s in @("'Z:'", "'Y:'", "'X:'", "'W:'", "'V:'", "'U:'", "'T:'", "'R:'", "'Q:'", "'P:'", "'O:'", "'N:'", "'M:'", "'L:'", "'K:'", "'J:'", "'H:'", "'G:'", "'F:'", "'E:'", "'D:'", "'B:'", "'A:'"))
{
$testdrv = Get-WmiObject -Class win32_volume -Filter "DriveLetter=$s"
if ($testdrv -eq $null)
{
$s = $s.Trim([char]0x0027)
Set-WmiInstance -input $driveI -Arguments @{DriveLetter=$s}
Write-Host I: has been moved to $s
break
}
}
}
$diary = Get-WmiObject -Class win32_volume -Filter "Label='My Diary'"
if ($diary.DeviceID.Contains("7899c0f7-f556-11e4-9cf2-7071bc4ab2b5") -And "$diary.SerialNumber = '-1675536360'")
{
Set-WmiInstance -input $diary -Arguments @{DriveLetter="I:"}
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
exit
} else {
Write-Host Error Occured!
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
exit
}