script to change drive letter

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

  1. MARKZ1ON

    MARKZ1ON MDL Junior Member

    May 22, 2020
    51
    2
    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 Addicted

    Jul 30, 2009
    755
    397
    30
  3. MARKZ1ON

    MARKZ1ON MDL Junior Member

    May 22, 2020
    51
    2
    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
    356
    588
    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
    51
    2
    0
    thank you, i am going to try this. can i also ask for the script to rename drive C?
     
  6. adric

    adric MDL Addicted

    Jul 30, 2009
    755
    397
    30
    I use diskpart in setupcomplete all the time that's what the /s is for (script)