Monday, May 14, 2012

PowerShell - Reorder/Rename CDROM/DVDROM devices in reverse alphabetical order

Title:  Reorder CDROM/DVDROM Drive Letters in Reverse Alpha

If you reorder your CDROM/DVDROM drives in reverse alphabetical order in your environment, you may have use for this script.  If you have one or more "disk drives" on a system, you can run this script and it will reorder them in reverse alphabetical order. 

  1. If you have a single drive on a single system, if you run this script, it will be relablelled as the "Z:" drive.
  2. If you have multiple drives on a single system (e.g. E:, F:, G:), they will be relabelled as Z:, Y:, X:, respectively.
Known Issues/Limitations:
  1. Does not account for drives already in use.
  2. Does not account for the potential of a large number of disk drives that would be greater than 26.

$CDROMs = @(Get-WmiObject Win32_Volume -Filter "DriveType=5")
$Alpha = @()
65..90 | % { $Alpha += [char]$_ }
for ($x=0; $x -lt $CDROMs.Count; $x++) {
    $idx = 25 - $x
    $CDROMs[$x] | Set-WmiInstance -Arguments @{DriveLetter = "$($Alpha[$idx])`:" }

1 comment: