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

    • Camtasia 2026.1.3 by Razvan Serea TechSmith Camtasia is the complete professional solution for high-quality screen recording, video editing and sharing. Camtasia 2026 makes editing your videos easier, and faster than ever. The new editor is packed with enhanced video processing, all-new production technology, an innovative library, and stock videos and other creative assets to help you create more polished, professional videos. No video experience needed. Anyone can create informative, engaging videos. Create professional, eye-catching videos: Add special video effects - Apply Behaviors that are perfectly designed to animate your text, images, or icons. Get a crisp, polished look without being a professional video editor. Drag-and-drop your edits - What you see is what you get. Every effect and element in your video can be dropped and edited directly in the preview window. And you can edit at resolutions up to beautiful 4K, for clear video at any size. Get exceptional performance - Camtasia takes full advantage of your computer’s processor with 64-bit performance. You’ll get fast rendering times and enhanced stability—even on your most complex projects. Camtasia 2026.1.3 changelog: Feature Updates Improved keyboard navigability in tool panels. Improved screen reader accessibility of headings in Preferences. Tool panels can now be resized using a keyboard-navigable control. Updated color of folder icon in User Library tab for better visibility. Grouped media now render a composite waveform considering all audio media within that group. Added Long Path Aware to the manifest of Editor and Recorder. Performance Improvements Improved performance for editing groups on the timeline. Improved the project loading performance when timeline has lots of trec media with cursor data. Updates for IT Administrators Updated cpp-httplib from 0.38.0 to 0.43.3. Updated expat from 2.7.4 to 2.8.0. Updated freetype from 2.13.3 to 2.14.3. Updated harfbuzz from 13.0.1 to 14.2.0. Updated libpng16 from 1.6.55 to 1.6.58. Updated pango from 1.57.0 to 1.57.1. Updated girepository from 2.86.3 to 2.88.0. Updated pcre2-posix from 10.47.0 to 12.0.2. Added new harfbuzz-gpu.dll. Updated FFmpeg from 7.1.1 to 7.1.2. Updated aom from 3.11.0 to 3.13.1. Updated dav1d from 1.5.0 to 1.5.1. Updated ogg from 1.3.5 to 1.3.6. Updated SDL2 from 2.32.4 to 2.32.10. Updated zlib from 1.3.1 to 1.3.2. Updated Nalpeiron binaries to version 4.4.69.3. Bug Fixes Fixed an issue which prevented some user submitted crash reports from being sent. Fixed a potential memory leak when decoding HEVC or VP9 video. Fixed a potential crash when trying to delete a range selection on a magnetic track. Fixed a bug with the Properties Panel showing stale properties when only a caption is selected on the timeline. Fixed an issue that could prevent the Opacity and Blur properties from being changed in the Background Removal effect. Fixed an issue where larger Camtasia online projects may fail to open in Camtasia Editor. Table of contents thumbnails are no longer created for Smart Player exports with no table of contents. Fix resetting skew revert to revert just skew and not scale as well. Fixed editing in Snagit with snagX file with Unicode characters. Fixed a bug where grouped visual media could be cropped in some cases. Fixed importing SnagX files with Unicode characters. Localization fixes. Download: Camtasia 2026.1.3 | 309.0 MB (Shareware) View: Camtasia Homepage | Tutorials | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • yeah it seems to be Edge only. The dialog buttons work as expected in Chrome and Firefox. The phone is using Android 16 (OneUI 8.5) and Edge version  149.0.4022.53
    • I'm not aware of this issue, but to help the other guys.  What version of Android are you using? Did you try a different browser? To see if Edge is the issue here.
    • I agree when are you going to read this (really poor BTW) article? Here is a better article so you actually know what is going on and answers questions you had in other comments --> https://arstechnica.com/gadgets/2026/05/speed-boosting-low-latency-profile-is-one-of-the-improvements-coming-to-windows-11/ It is unclear if one will be able to disable the new profile at this point but I am not seeing any reason why one would.
  • Recent Achievements

    • One Month Later
      Jamswaz earned a badge
      One Month Later
    • Week One Done
      Jamswaz earned a badge
      Week One Done
    • Rookie
      Marzoid went up a rank
      Rookie
    • Community Regular
      coch went up a rank
      Community Regular
    • One Year In
      slackerzz earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      512
    2. 2
      PsYcHoKiLLa
      188
    3. 3
      +Edouard
      157
    4. 4
      Steven P.
      83
    5. 5
      ATLien_0
      75
  • Tell a friend

    Love Neowin? Tell a friend!