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