[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

script the NETSH commands

Posted on 2009-04-23
9
Medium Priority
?
1,412 Views
Last Modified: 2012-05-06
I need to enter the commands below in batch file. how can I do that?
I tried it but it just open Netsh window and stays there.

Adding DHCP option 60 to Windows 2003 DHCP server
By default, option 60 is not set on Windows® 2003. If the OS deployment server is running on the same host as the DHCP server, you have to add this option and set its value to PXEClient in order to tell PXE clients where to find the OS deployment server.
Open a command window.
Enter netsh
Enter dhcp 4.
Enter server \\hostname or server ip_address. A command prompt that says: dhcp server> is displayed.
Enter add optiondef 60 PXEClient STRING 0 comment=option added for PXE support
Enter set optionvalue 60 STRING PXEClient
To confirm that everything has been set correctly, enter:
show optionvalue all
0
Comment
Question by:jskfan
  • 4
  • 4
9 Comments
 
LVL 10

Accepted Solution

by:
TakedaT earned 1500 total points
ID: 24218386
If you have the pc configured the way you want it.  You can dump the config to a file using "netsh dump>c:\file.txt", then in your batch file execute the file "netsh exec c:\file.txt".  

If that isnt an option, Im not exactly sure of the syntax of the netsh command and cant test your commands because I dont have a 2003 server to test on.  You can try to concatenate the commands together in the batch like so:

netsh dhcp 4 server \\hostname add optiondef 60 PXEClient STRING 0
netsh dhcp 4 server \\hostname set optionvalue 60 STRING PXEClient
netsh dhcp 4 server \\hostname show optionvalue all



0
 

Author Comment

by:jskfan
ID: 24219430
what I wanted is, instead of typing those commands in a Netsh window and wait for the reply and type the next command and so on. I want just to put them all in one batch file and run the file.
0
 
LVL 10

Expert Comment

by:TakedaT
ID: 24219562
I understand what you were saying.  What I am saying is that instead of passing the baton to the netsh program and it waiting for you, just give the program what it wants in one shot so it doesnt wait for input.  I have dont it in the past.  For example, in my login script, i disable dynamic dns with the following command on one line:

netsh interface ip set dns name=Local Area Connection source=dhcp register=none>nul

This same command can be done by talking to the netsh program, but it was easier to use it as a one liner in the batch, because the program got what it wanted and exited, not waiting for an answer from the user.
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.

 

Author Comment

by:jskfan
ID: 24222436

do you mean I will put the following commands in a text file for instance fike.txt:
<<netsh
dhcp 4.
server \\hostname or server ip_address. A command prompt that says: dhcp server> is displayed.
add optiondef 60 PXEClient STRING 0 comment=option added for PXE support
set optionvalue 60 STRING PXEClient >>

then run:
Netsh dump c:\file.txt
netsh exec c:\file.txt

Correct?



0
 
LVL 10

Expert Comment

by:TakedaT
ID: 24224592
The Netsh dump c:\file.txt and netsh exec c:\file.txt option is seperate from my other suggestion.  If you have the settings correct on a machine to dump from, then you can find those settings in the dump file and exec it on the other pcs.

The other suggestion is totally seperate.  If you are familiar with telnet, it is the same principle.  Once you type telnet in the command prompt, the command promt gives control over to telnet and telnet waits for you to enter its own commands.  Netsh is similar in this way.  But, if you concatenate all of the seperate commands into one larger command, then the netsh will execute the command and give control back to the command prompt, allowing your batch file to continue.  You are basically typing one part of the command at a time.  If you type all of it at once, the netsh program will be happy and finish.

Since you said that you want it in a batch file, I didnt suggest this, but if you use a vbscript, you could also use the sendkeys method to do the typing for you.
0
 

Author Comment

by:jskfan
ID: 24239568
<<<But, if you concatenate all of the seperate commands into one larger command, then the netsh will execute the command and give control back to the command prompt>>>

can you write it down here?
0
 
LVL 10

Expert Comment

by:TakedaT
ID: 24241181
If I knew the syntax of your particular command needs, I would have done that already.  The fact is, the dhcp part is only available on a win2003 server that has dhcp running on it.  I dont have access to a box w/ win2003.  You could probably figure it out by trial and error.  I put my best guess as to what it MIGHT be in my first post.
0
 

Author Comment

by:jskfan
ID: 24285585
these are the individual commands that need to be run in a batch file:

 netsh
 dhcp
 server \\hostname or server ip_address.
 add optiondef 60 PXEClient STRING 0 comment=option added for PXE support
 set optionvalue 60 STRING PXEClient
0
 

Expert Comment

by:tbourns
ID: 33747514
awesome worked, thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

WARNING:   If you follow the instructions here, you will wipe out your VTP and VLAN configurations.  Make sure you have backed up your switch!!! I recently had some issues with a few low-end Cisco routers (RV325) and I opened a case with Cisco TA…
In this article I will be showing you how to subnet the easiest way possible for IPv4 (Internet Protocol version 4). This article does not cover IPv6. Keep in mind that subnetting requires lots of practice and time.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

872 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