Batch to reassign drive letter based on volume name

I have a "WINPE" volume and I am trying to get a batch script that will assign it drive letter "Z:"

Someone gave me the script below but it does not work

  Set mm=%date:~4,2%
    Set dd=%date:~7,2%
    Set yyyy=%date:~10,4%
    Set h=%time:~0,2%
    if "%h:~0,1%"==" " set h=0%time:~1,1%
    set m=%time:~3,2%
    start /min diskpart.exe
    diskpart /s script.txt > output.txt
    for /f "tokens=3,4 delims= " %%a in (output.txt) do if /i %%b==WINPE if /i %%a==Z goto end1
    for /f "tokens=3,4 delims= " %%a in (output.txt) do if /i %%b==WINPE if /i not %%a==Z goto Assign=Z
    :AssignZ
    echo Assigning Z
    for /f "tokens=1,2 delims= " %%a in ('type output.txt ^| find /i "WINPE"') do echo select %%a %%b > assigng.txt
    echo assign letter = Z >> assigng.txt
    diskpart /s assigng.txt
    del /f/ q assigng.txt
    echo %mm%/%dd%/%yyyy% %h%:%m% >> logs.txt
    echo Drive letter was changed and should be assigned properly >> logs.txt
    taskkill /f /im diskpart.exe
    del /f /q output.txt
    exit
    :end1
    echo %mm%/%dd%/%yyyy% %h%:%m% >> logs.txt
    echo drive letter assigned properly >> logs.txt
    taskkill /f /im diskpart.exe
    del /f /q output.txt
    exit

July 24th, 2015 4:54pm

This needs a little more thinking about:

  • Why would you want to do this?
  • What is the purpose of the Date/Time variables in your script?
  • What would you do if drive letter Z: was already used?
  • What would you do if the WinPE volume was already assigned a drive letter?
  • Are you prepared to put some of your own effort into this project or do you expect someone to deliver a turn-key solution for you?

Free Windows Admin Tool Kit Click here and download it now
July 24th, 2015 6:55pm

This needs a little more thinking about:

  • Why would you want to do this?
  • What is the purpose of the Date/Time variables in your script?
  • What would you do if drive letter Z: was already used?
  • What would you do if the WinPE volume was already assigned a drive letter?
  • Are you prepared to put some of your own effort into this project or do you expect someone to deliver a turn-key solution for you?

 I want to have a create ready to deploy a wim file from my WINPE USB Drive.  I do not need the date or time.  If WINPE was already assigned a drive letter I would need it changed to Z: because my other scripts are dependent on the z: drive weather from network or usb 
July 24th, 2015 7:08pm

Your reply leaves two questions unanswered. Please note that this is not a trivial exercise.
Free Windows Admin Tool Kit Click here and download it now
July 25th, 2015 1:52am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics