script to change drive letter

Discussion in 'Scripting' started by MARKZ1ON, Jul 12, 2020.

  1. MARKZ1ON

    MARKZ1ON MDL Junior Member

    May 22, 2020
    59
    3
    0
    Is it possible to change drive letter (and rename) of D in setupcomplete.cmd? I only have 2 drives, and I always change the second one to drive Z after an OS reinstall.

    thank you,
     
  2. adric

    adric MDL Expert

    Jul 30, 2009
    1,406
    1,544
    60
  3. MARKZ1ON

    MARKZ1ON MDL Junior Member

    May 22, 2020
    59
    3
    0
    thanks, i've seen the diskpart command as well as powershell. though what i would like to accomplish is doing it automated/silent through setupcomplete.cmd script.
     
  4. Thomas Dubreuil

    Thomas Dubreuil MDL Senior Member

    Aug 29, 2017
    363
    624
    10
    ps command is super simple!
    Get-Partition -DriveLetter A | Set-Partition -NewDriveLetter B
    (without the two dots after drive letter)

    In your .cmd script you can write it like
    powershell.exe -NoProfile -ExecutionPolicy Bypass -c "&{Get-Partition -DriveLetter D | Set-Partition -NewDriveLetter Z}" >nul 2>&1
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. MARKZ1ON

    MARKZ1ON MDL Junior Member

    May 22, 2020
    59
    3
    0
    thank you, i am going to try this. can i also ask for the script to rename drive C?
     
  6. adric

    adric MDL Expert

    Jul 30, 2009
    1,406
    1,544
    60
    I use diskpart in setupcomplete all the time that's what the /s is for (script)