Backup DNS Server/s
I have a problem with this script here
for /f "tokens=3" %%a in ('netsh interface ip show config ^| find /i "DHCP Enabled"') do set DHCP=%%a
If /i "%dhcp%" == "Yes" (
REM do command here
) Else (
REM script to backup DNS servers to environment variables
)
I've tried numerous ways using the first for /f example to try and get the DNS Server entries int开发者_StackOverflow社区o environmental variables to be used later.
So basically I'm looking for a way to backup the dns server/s to environment variable/s (primary/secondary DNS) if DHCP is disabled.
For this batch to properly run, make sure you enable delayed expansion. Just add setlocal ENABLEDELAYEDEXPANSION
at the beginning of your batch file.
But it will not "get the DNS Server entries into environment variables", which I believe is a different question.
Look into PowerShell It is a lot more flexible than the old batch file way of doing things.
精彩评论