I saw the Get-NextFreeDrive
function in this answer and I wondered if there was a more efficient way to do this. It appears that the function in the linked answer keeps going through all the letters even if it has already found a free drive letter.
Launch Regedit, navigate to HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices. Check whether there is a device is shown as being mounted at the specific drive letter. 2>. Then, right-click the drive letter that you want and choose Rename from the list menu, and change the letter to any other used letter to free up it.
1] Manually Show Missing Drive LettersFrom the Start search, open Folder Options and click the 'View' tab. Scroll down the list of options until the 'Show drive letters' option is seen. Simply check the box marked against this option. Click 'Apply', then 'OK'.
You have to rename the current F drive letter to an unused letter. That frees up the letter you want to use. Use Disk Management to change it. Warning-- this will cause the same problem you are having now and will break connections to programs on the changed drive/partition.
Once you run out of drive letters Windows will force you to mount drives to a NTFS folder or mount points rather than a drive letter.
Here's what I came up with. I need the last available drive letter from A to Z.
$AllLetters = 65..90 | ForEach-Object {[char]$_ + ":"}
$UsedLetters = get-wmiobject win32_logicaldisk | select -expand deviceid
$FreeLetters = $AllLetters | Where-Object {$UsedLetters -notcontains $_}
$FreeLetters | select-object -last 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With