views:

108

answers:

2

Hi guys,

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 into environmental variables to be used later.

So basically I'm lookin' for a way to backup the dns server/s to environement variable/s (primary/secondary dns) if DHCP is disabled.

Thanks and God Bless,

Merry Xmas and Happy New Year

John

+1  A: 

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.

PA
A: 

Look into PowerShell It is a lot more flexible than the old batch file way of doing things.

Chris Lively
I would look into PowerShell, because I know its more 'powerful' :PBut the point of using Batch is to make it generic, and so it can run on all flavours of Windows (XP/Vista/7)
John
Powershell is available to be installed on everything from XP forward. 32 and 64 bit; desktop and server OS's.
Chris Lively