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 :)

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!

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.

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

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            
   # ======================================================================

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.

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. 

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.

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

    • No registered users viewing this page.
  • Posts

    • Wow, imagine you dump hundreds of hours into completing things and unlocking stuff and you lose it all. Back in the day when cheats were built into games, you could at least unlock things again that way without spending hundreds of hours again. But those days are long gone for some reason as no one builds cheats into games anymore. So it's even more painful that studio that's on its 6th installment **** it up so badly.
    • Spotify finally removes the disco ball app icon in the latest update by Ivan Jenic Image: Spotify Spotify has just released an update that removes its now infamous disco ball icon. The update reverts the app icon to the familiar flat green logo after weeks of mixed reactions online. The icon arrived on May 13 as part of the company's 20th anniversary celebration and was always intended to be temporary, though Spotify only confirmed that after the backlash started. The disco ball took the internet by storm, as the reception was split. A vocal group of users called it ugly and disorienting, with some iOS users noting that the 3D glowing effect made the app look like it was stuck mid-update. On the other end, the icon picked up a following of its own. Its retro, three-dimensional look immediately stood out against the flat, minimalist aesthetic that has dominated app design for years. It even started a small movement, spawning what people started calling "discomorphism," a mashup of disco and skeuomorphism. Other brands started posting disco ball versions of their own logos, probably in an effort to ride the wave of memes that flooded the internet during late May. Spotify has had a turbulent relationship with its user base lately. Besides the disco ball icon, which certainly wasn't appreciated by everyone, the company has also received backlash for its willingness to include AI-generated music on its platform. On May 17, Spotify promised the old icon would return “in a few weeks.” And now it looks like that time has finally arrived. So, whether you liked the disco ball or it made you uncomfortable, it’s now gone for good. The next time you update the Spotify app on your phone, the old, flat-design icon will return.
  • Recent Achievements

    • One Year In
      slackerzz earned a badge
      One Year In
    • One Year In
      highriskpaym earned a badge
      One Year In
    • One Month Later
      highriskpaym earned a badge
      One Month Later
    • Week One Done
      highriskpaym earned a badge
      Week One Done
    • Week One Done
      FBSPL earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      519
    2. 2
      PsYcHoKiLLa
      197
    3. 3
      +Edouard
      157
    4. 4
      Steven P.
      84
    5. 5
      ATLien_0
      75
  • Tell a friend

    Love Neowin? Tell a friend!