Powershell - 25 DHCP Scopes Creation - 2K8 R2


Recommended Posts

I found a few options but they are for Windows 2012.

 

http://blogs.technet.com/b/heyscriptingguy/archive/2013/01/15/use-powershell-to-create-multiple-dhcp-scopes-on-dhcp-servers.aspx

 

http://blogs.technet.com/b/heyscriptingguy/archive/2013/01/14/use-powershell-to-create-ipv4-scopes-on-your-dhcp-server.aspx

 

and others but just seems those cmds arent available (and i cant upgrade PS right now).

 

 

Here is a snippet of the ranges needed:

 

post-698-0-83774600-1421055615.png

 

I'm not so good with Powershell but learning as i go :)

Link to comment
Share on other sites

Does it have to be power shell? You can do this with a vbscript or batch file utilizing netsh. When I get to a desktop and can type properly, I can give examples.

Link to comment
Share on other sites

I created one using batch file but i guess powershell is what the boss wanted since it took a while.

 

However it took a while because i didnt know how to properly import a CSV file and pipe the commands in.

 

So basically i ended up creating something like this

REM -- Batch file to create a scopes on a DHCP server      
       
REM       
      
REM -- Creating Scope 10.220.96.128 with range 10.220.96.170-254, Gateway 10.220.96.129
      
netsh dhcp server 10.216.67.20 add scope 10.220.96.128 255.255.255.128 "VLAN 101" set state 0

netsh dhcp server 10.216.67.20 scope 10.220.96.128 add IPRANGE 10.220.96.170 10.220.96.254

netsh dhcp server 10.216.67.20 scope 10.220.96.128 set optionvalue 003 IPADDRESS 10.220.96.129

netsh dhcp server 10.216.67.20 scope 10.220.96.128 set state 0


REM -- Creating Scope 10.220.97.0 with range 10.220.97.12-62 Gateway 10.220.97.1
      
netsh dhcp server 10.216.67.20 add scope 10.220.97.0 255.255.255.192 "VLAN 120" set state 0

netsh dhcp server 10.216.67.20 scope 10.220.97.0 add IPRANGE 10.220.9.112 10.220.97.62

netsh dhcp server 10.216.67.20 scope 10.220.97.0 set optionvalue 003 IPADDRESS 10.220.97.1

netsh dhcp server 10.216.67.20 scope 10.220.97.0 set state 0


REM -- Creating Scope 10.220.97.64 with range 10.220.97.76-126, Gateway 10.220.97.65
      
netsh dhcp server 10.216.67.20 add scope 10.220.97.64 255.255.255.192 "VLAN 121" set state 0

netsh dhcp server 10.216.67.20 scope 10.220.97.64 add IPRANGE 10.220.97.76 10.220.97.126 

netsh dhcp server 10.216.67.20 scope 10.220.97.64 set optionvalue 003 IPADDRESS 10.220.97.65

netsh dhcp server 10.216.67.20 scope 10.220.97.64 set state 0

Which as you can imagine is a pain if you had 100 scopes to create!

Link to comment
Share on other sites

There are so many powershell examples for this out there, Check out The Scripting Guys website.

 

Linked to those above but mentioned some were for 2012 and i am on 2008 R2. Also PowerShell cant get upgraded this moment because of some other changes going on so for example:

 

Add-DHCPServerV4Scope

 

Does not work in the current setup. I would love if that was the case but sadly not.... well not yet. We will be doing some 2012 R2 upgrades later but for now just gotta work with what we got.

Link to comment
Share on other sites

I found a few options but they are for Windows 2012.

 

http://blogs.technet.com/b/heyscriptingguy/archive/2013/01/15/use-powershell-to-create-multiple-dhcp-scopes-on-dhcp-servers.aspx

 

http://blogs.technet.com/b/heyscriptingguy/archive/2013/01/14/use-powershell-to-create-ipv4-scopes-on-your-dhcp-server.aspx

 

and others but just seems those cmds arent available (and i cant upgrade PS right now).

 

 

Here is a snippet of the ranges needed:

 

attachicon.gifDHCP Scopes.png

 

I'm not so good with Powershell but learning as i go :)

Same here.  I just wish there was more I could do @ home to learn.

I think the best way to learn for me would be to identify a problem, then learn how to solve it with PS - only problem is @ home, I dont have server/network problem/issues

Link to comment
Share on other sites

you can use netsh -f config_dhpc.txt

 

The text file will contain the following (I did the first 2).  You can do a find and replace to the values, but it wouldn't be a fun task for 100's of scopes to add in...then again you probably wouldnt be adding in this many scopes at one time unless you were trying to do a manual restore either from memory or documentation.  I can't see this being a very easy task. 

# =====================================
#     Add Scope                        
# =====================================

Dhcp Server \\mydhcpserver add scope 10.220.96.128 255.255.255.128 "VLAN 101" ""
Dhcp Server \\mydhcpserver Scope 10.220.96.128 set state 1
Dhcp Server \\mydhcpserver Scope 10.220.96.128 set delayoffer 0

   # ======================================================================
   #  Start Add Ipranges to the Scope 10.220.96.128, Server mydhcpserver                  
   # ======================================================================


Dhcp Server \\mydhcpserver Scope 10.220.96.128 Add iprange 10.220.96.170 10.220.96.254
Dhcp Server \\mydhcpserver scope 10.220.96.128 set napstate Off

   # ======================================================================
   #  End   Add Ipranges to the Scope 10.220.96.128, Server mydhcpserver                  
   # ======================================================================


   # ======================================================================
   #  Start Add Excluderanges to the Scope : 10.220.96.128, Server : mydhcpserver         
   # ======================================================================



   # ======================================================================
   #  End   Add Excluderanges to the Scope : 10.220.96.128, Server : mydhcpserver         
   # ======================================================================


   # ======================================================================
   #  Start Add OptionValues to the Scope : 10.220.96.128, Server : mydhcpserver          
   # ======================================================================

Dhcp Server \\mydhcpserver Scope 10.220.96.128 set optionvalue 51 DWORD "691200"
Dhcp Server \\mydhcpserver Scope 10.220.96.128 set optionvalue 3 IPADDRESS "10.220.96.129"

   # ======================================================================
   #  End   Add OptionValues to the Scope : 10.220.96.128, Server : mydhcpserver          
   # ======================================================================


   # ======================================================================
   #  Start Add ReservedIp to the Scope : 10.220.96.128, Server : mydhcpserver            
   # ======================================================================


Dhcp Server \\mydhcpserver v4 Scope 10.220.96.128 Set NameProtection enable= 0
Dhcp Server \\mydhcpserver Scope 10.220.96.128 Set DnsConfig 1 0 1 0

   # ======================================================================
   #  End   Add ReservedIp to the Scope : 10.220.96.128, Server : mydhcpserver            
   # ======================================================================


Dhcp Server \\mydhcpserver add scope 10.220.97.0 255.255.255.192 "VLAN 120" ""
Dhcp Server \\mydhcpserver Scope 10.220.97.0 set state 1
Dhcp Server \\mydhcpserver Scope 10.220.97.0 set delayoffer 0

   # ======================================================================
   #  Start Add Ipranges to the Scope 10.220.97.0, Server mydhcpserver                  
   # ======================================================================


Dhcp Server \\mydhcpserver Scope 10.220.97.0 Add iprange 10.220.97.12 10.220.97.62
Dhcp Server \\mydhcpserver scope 10.220.97.0 set napstate Off

   # ======================================================================
   #  End   Add Ipranges to the Scope 10.220.97.0, Server mydhcpserver                  
   # ======================================================================


   # ======================================================================
   #  Start Add Excluderanges to the Scope : 10.220.97.0, Server : mydhcpserver         
   # ======================================================================



   # ======================================================================
   #  End   Add Excluderanges to the Scope : 10.220.97.0, Server : mydhcpserver         
   # ======================================================================


   # ======================================================================
   #  Start Add OptionValues to the Scope : 10.220.97.0, Server : mydhcpserver          
   # ======================================================================

Dhcp Server \\mydhcpserver Scope 10.220.97.0 set optionvalue 51 DWORD "691200"
Dhcp Server \\mydhcpserver Scope 10.220.97.0 set optionvalue 3 IPADDRESS "10.220.97.1"

   # ======================================================================
   #  End   Add OptionValues to the Scope : 10.220.97.0, Server : mydhcpserver          
   # ======================================================================


   # ======================================================================
   #  Start Add ReservedIp to the Scope : 10.220.97.0, Server : mydhcpserver            
   # ======================================================================



   # ======================================================================
   #  End   Add ReservedIp to the Scope : 10.220.97.0, Server : mydhcpserver            
   # ======================================================================

Link to comment
Share on other sites

Kix is very powerful and easy to view and setup. Works every time without fail. Don't have to pray to the ms gods for gpo to function and don't need a ton of coding to get things to function.

Map a drive with vbscript based on group membership, I can do it in 3 lines with kix. I can add a printer with one line, I can default a printer in another line.

Link to comment
Share on other sites

LOL! 

 

If you need to write login scripts still (especially in vbscript and kix), you don't understand group policy. I can create printers, drive mappings, and set defaults all with a few mouse clicks. I haven't prayed to MS in a long time (never), and GPO seems to work 100% of the time for me. 

Link to comment
Share on other sites

They work when I need a config change. When I need immediate gratification they don't work fast enough. How are you pushing drive mappings that need to happen in 10 minutes? Or do you wait the 45 minutes to an hour for replication to take place?

I add the user to the group then have them log off and back on a minute later. No waiting or having them run commands to get group policy to reapply.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.