Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Urgent Help need creating a NETSH login script

Posted on 2009-07-14
18
Medium Priority
?
449 Views
Last Modified: 2012-05-07
Here is my problem. I need to create a login script that will update the static DNS and WINS informatino on client workstation ONLY if these settings are already staticalyy assigned.

In a nutshell this script needs to check to see if the DNS settings are DHCP or Static basised. If they are DHCP the script should not run

Please help
0
Comment
Question by:compdigit44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 8
18 Comments
 
LVL 30

Expert Comment

by:Britt Thompson
ID: 24853704
Looks like someone already needed that here:http://www.experts-exchange.com/Networking/Misc/Q_21326998.html

@leew
for /f "tokens=3" %%a in ('netsh interface ip show config ^| find /i "DHCP Enabled"') do set DHCP=%%a
If /i "%dhcp%" == "Yes" (
    netsh interface ip set dns "Local Area Connection" dhcp
) Else (
    netsh interface ip set dns "Local Area Connection" static 10.0.0.3
)

You could actually avoid the environment variable entirely with this:

for /f "tokens=3" %%a in ('netsh interface ip show config ^| find /i "DHCP Enabled"') do (
If /i "%%a" == "Yes" (
    netsh interface ip set dns "Local Area Connection" dhcp
) Else (
    netsh interface ip set dns "Local Area Connection" static 10.0.0.3
)
)
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 24853749
Or, more comprehensive,

netsh int ip dump | findstr "dns wins" | findstr source=static && (
  rem your netsh commands here
)

0
 
LVL 20

Author Comment

by:compdigit44
ID: 24855104
This is not quite what I was looking for...

I need this script to run ONLY on clients who have STATIC DNS & WINS enteries. please note some clients are set to DHCP for there TCP/IP settings but DNS is startic. I need this script to look for all static DNS & WINS and update these enteries only!!!!!!!!!!!!!!!!!!!!!!!
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 71

Expert Comment

by:Qlemo
ID: 24856998
My script should work for exactly this situation. It's checking the DNS and WINS entries only for being static.
0
 
LVL 20

Author Comment

by:compdigit44
ID: 24858502
OK this is what my scritp looks like. Right now I just paused on screen and never changes my static DNS / WINS settings

netsh int ip dump | findstr "dns wins" | findstr source=static && (netsh interface ip set dns "Local Area Connection" static 1.2.3.4
netsh interface ip add dns "Local Area Connection" 1.2.3.4 index=2
netsh interface ip set wins "Local Area Connection" static 1.2.3.4
netsh interface ip add wins "Local Area Connection" 1.2.3.4index=2)
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 24859878
Just tried, and it works fine for me. Does it output the config lines found?
0
 
LVL 20

Author Comment

by:compdigit44
ID: 24860670
Whn I just run the first part of the script:

netsh int ip dump | findstr "dns wins" | findstr source=static
It works and list the connection information "IF" it has static DNS & WINS enteries which is what  want. The problem is this inforamtion is not beening replacement with the correct DNS & WINS information from my scrupt. Don't I need an if statement somewhere??????
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 24861464
No, the && is like an IF. If the previous command "succeeds", i.e. returns a errolevel of 0, the command after && is executed. You can try by using

netsh int ip dump | findstr "dns wins" | findstr source=static && echo --- It is STATIC ---


The complete command as you posted above should give the same output, plus the results of your netsh commands, which should be 4 times "OK!".

0
 
LVL 20

Author Comment

by:compdigit44
ID: 24862254
Do I need the ( ) ??? in this script?
0
 
LVL 20

Author Comment

by:compdigit44
ID: 24862293
Right now the script RUN and updates the DNS but it RUNS on my client who have DNS set by DHCP which is what I do not want
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 24863471
You need the () to build a single block executed only if the condition applies (findstr finding "source=static"). If you omit the parentheses, only the first command is executed conditional, the remainder always.
0
 
LVL 20

Author Comment

by:compdigit44
ID: 24865178
Still now working... the script is working but it is running no matter if the current DNS settings are DHCP or static... :-(
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 24870201
Your are doing something wrong. You confirmed that
netsh int ip dump | findstr "dns wins" | findstr source=static
is displaying the correct lines.
netsh int ip dump | findstr "dns wins" | findstr source=static && echo --- It is STATIC
Should display the same lines, and the text "--- It is STATIC" if any of the entries contain source=static.
netsh int ip dump | findstr "dns wins" | findstr source=static && ^
(
netsh interface ip set dns "Local Area Connection" static 1.2.3.4
netsh interface ip add dns "Local Area Connection" 1.2.3.4 index=2
netsh interface ip set wins "Local Area Connection" static 1.2.3.4
netsh interface ip add wins "Local Area Connection" 1.2.3.4index=2
)
Is applied if at least one of DNS or WINS setting is static.

0
 
LVL 20

Author Comment

by:compdigit44
ID: 24870222
Do I need the ^ after the &&?
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 24870239
If you write the ( into the next line - yes. Instead you can use

netsh int ip dump | findstr "dns wins" | findstr source=static && (
netsh interface ip set dns "Local Area Connection" static 1.2.3.4
netsh interface ip add dns "Local Area Connection" 1.2.3.4 index=2
netsh interface ip set wins "Local Area Connection" static 1.2.3.4
netsh interface ip add wins "Local Area Connection" 1.2.3.4index=2
)

if you like that more.
0
 
LVL 20

Author Comment

by:compdigit44
ID: 24870332
I noticed that when this script runs it updates both my Local Area Connection and Network Adapter Local but I do not see Network Adapter Connection listed any where
0
 
LVL 71

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 24872245
Ok, we have to be more specific then:

netsh int ip dump | findstr "dns wins" | findstr /c:"Local Area Connection" | findstr source=static && (
netsh interface ip set dns "Local Area Connection" static 1.2.3.4
netsh interface ip add dns "Local Area Connection" 1.2.3.4 index=2
netsh interface ip set wins "Local Area Connection" static 1.2.3.4
netsh interface ip add wins "Local Area Connection" 1.2.3.4index=2
)

0
 
LVL 20

Author Closing Comment

by:compdigit44
ID: 31603463
This worked perfectly....

Thanks Again
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here's a look at newsworthy articles and community happenings during the last month.
How to deal with a specific error when using the Enable-RemoteMailbox cmdlet to create a mailbox in the cloud-based service, for an existing user in an on-premises Active Directory.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question