@echo off

rem set name for media ...
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set OSLABEL=W10-%YY%%MM%%DD%

set OSCDPATH="%ProgramFiles(x86)%\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg"
set ISOFILE=%SystemDrive%\temp\%OSLABEL%.iso

IF %1.==. GOTO USAGE

echo ================================
echo Make ISO file from Media ...
echo ================================
echo.

set DRIVE=%1

if /I %DRIVE% == %SystemDrive% (
  echo ERROR: cannot use drive %DRIVE% !
  exit /b
)

echo using drive [ %DRIVE% ] ...
echo.

if NOT EXIST %DRIVE% (
  echo ERROR: drive %DRIVE% not found!
  exit /b
)

rem =====
rem MAIN
rem =====

del /F %ISOFILE% 2>nul

if EXIST %ISOFILE% (
  echo ERROR: cannot delete/create %ISOFILE%!
  echo HINT: maybe it is mounted by Virtualbox or some other tool?
  exit /b
)

if NOT EXIST %OSCDPATH%\oscdimg.exe (
  echo ERROR: cannot find oscdimg.exe!
  echo HINT: is "Assessment and Deployment Kit (ADK)" installed?
  exit /b
)

%OSCDPATH%\oscdimg -l%OSLABEL% -m -u2 -b%OSCDPATH%\etfsboot.com %DRIVE%\ %ISOFILE%

echo.
echo ======
echo READY.
echo ======

GOTO END

:USAGE
echo "usage: %0 <DRIVE>"

:END

