Random bytes...

I wanted to write a script to change some drive volumes around for a new partitioning scheme.  Being me I wanted to do it in PowerShell, so I searched Google, Live, etc. to find a quick answer and ... found nothing.  Not a single person with a post on how to change a drive letter with PowerShell.  Maybe it is considered so easy no one has ever bothered blogging about it?   This needs to be corrected though, I believe, and so I shall.

  1. Grab the Win32_Volume WMI object and filter the results so you only get the drive letter you want. In my example I use E:.

    1. $volume = gwmi win32_volume | ?{$_.DriveLetter -eq "E:"}  
  2. Next up we enter an overly complex command to change the drive letter. In this case to D:.

    1. $volume.DriveLetter = "D:"  
  3. And finally we save the changes with a put().

    1. $volume.put()  

Seriously, that's it. And now for some random notes taken from my experimentation...

  • Use $_.Label if you don't know the drive letter, but know the volume name (like OS, Data, Vista, Local Disk, etc.).
  • If you want to remove the drive letter, use this command: $volume.DriveLetter = $null (you still need the put()).
  • Mounting the volume to a folder goes like this: $volume.AddMountPoint("C:\path") Be sure the directory exists first. new-item can be used to make one, and test-path can be used to check if it's there.

On a lighter note, I built a second system last weekend and work got me a KVM so I could switch between my work laptop and my new test system. It's a StarTech.com SV211KDVI. It can control two computers using DVI and USB for both mouse and keyboard. It also has a nice feature where you can switch between computers using a keyboard shortcut.

I panicked today while I was using it because it kept switching between computers without me pressing the button or using the keyboard shortcut. I was about to bust out a bucket of KFC as an offering to the tech deities when I figured out my possession problem. It turns out the switching happened every time I clicked into a VMware Infrastructure Client (VIC) console window. Not the one inside the VIC, which works fine, just a breakout console window. How random is that? VMware Tools apparently uses the some keyboard code that is identical to the one StarTech uses to switch computers. Freaky stuff.

#James Kehr
Get-Member $OW | ?{$_.title -eq "System Administrator"`
-and $_.certification -contains 'MCSE 2000, MCDST, Network+, A+'}

New-Variable -name company -value 'ORCS Web, Inc.' -description www.orcsweb.com | 1.888.313.9421’

blog comments powered by Disqus