Assign next available drive letter from command line other than diskpa


  1. Posts : 456
    Windows 10
       #1

    Assign next available drive letter from command line other than diskpa


    I was wondering if there is a way to assign the next available driveletter, without specifying a specific letter to a volume by using the command line other than "diskpart assign"?

    I was looking into wmic but only found out how to assign a specific driveletter and I would like to assign the next available driveletter. Any ideas?
      My Computer


  2. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #2

    Hello @ricardobohner,

    I do NOT have the exact answer that you are looking for, but, to find ALL available drives letters that are NOT in use, you could use this:

    Code:
    
    PowerShell $Available_Drives='ABCDEFGHIJKLMNOPQRSTUVWXYZ' -Split '' ^| Where-Object {$_ -NotIn ([System.IO.DriveInfo]::GetDrives().Name).Substring(0,1)}; Write-Host $Available_Drives

    The above also excludes the DVD drive letter if you have one !

    To find the next available drive letter is NOT straight forward as it would rely on if your current drive has missing drive letters in the structure. For example: C: D: H: M: N: Q: etc.

    I hope this helps.

    EDIT:

    I have just found this for you > Getting a Free Drive Letter

    There is one there that might interest you as you can also change Select-Object -First 1 to Select-Object -Last 1:

    Code:
    
    $DriveList = Get-PSDrive -PSProvider filesystem | foreach({($_.Root).Replace(":\","")})
    $AllDrives = [char[]]([int][char]'E'..[int][char]'Z')
    $NextDriveLetter = ($AllDrives | Where-Object { $DriveList -notcontains $_ } | Select-Object -First 1) + ":"
    Write-Host $DriveList `n; Write-Host $AllDrives `n; Write-Host $NextDriveLetter
    Last edited by Paul Black; 20 Sep 2023 at 08:27.
      My Computer


  3. Posts : 456
    Windows 10
    Thread Starter
       #3

    Thank you paul
      My Computer


  4. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #4

    ricardobohner said:
    Thank you paul
    You are VERY welcome.
      My Computer


  5. Posts : 4,595
    several
       #5

    @echo off
    vol Z: Y: X: W: V: U: T: S: R: Q: P: O: N: M: L: K: J: I: H: G: F: E: D: C: 1>nul 2>%temp%\erroutfile.txt
    for /F "tokens=5 delims=. " %%A in (%temp%\erroutfile.txt) do @set nextavailetter=%%A
    @echo Next available letter %nextavailetter%
    pause
      My Computer


  6. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #6

    Hello @SIW2,

    I ran the Script and it came back with drive letter E:, which is my DVD drive letter.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 14:39.
Find Us




Windows 10 Forums