setlocal for /f "delims=: tokens=1-2" %%c in ('ipconfig /all ^| find "DHCP"') do set GetDHCP=%%d endlocal & set GetDHCP=%GetDHCP:~1% echo %GetDHCP% > "C:\Program Files\bginfo\dhcp.txt"