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

    • Playground Games confirms Forza Horizon 6 save wipe bug by Taras Buria Forza Horizon 6 was launched last month to critical acclaim (check out our review here), and it became a smash hit in an instant. Now, weeks into the launch, with die-hard fans clocking hundreds of hours, Forza Horizon 6 is facing a serious issue: save wipes. After multiple complaints on Reddit and social media, the studio issued a statement. The problem with missing saves came shortly after Playground Games promised the initial batch of gameplay tweaks and improvements. Unfortunately, there seems to be no temporary fixes for those affected by unexpected save wipes. However, the studio published a new support document with a few important steps users should try. First, affected gamers should open a support ticket immediately (go here to file one) so that the support team can try recovering the lost progress by reverting to an earlier save. Playground Games says this should be done the same day the issue occurs. Meanwhile, gamers are urged not to start new play sessions or create new saves. The studio also published a few things gamers should try to avoid to prevent potential progress loss: Ensure your Gaming Services app on PC or XBOX Series X|S console is fully up to date. On XBOX Series X|S consoles, disable Quick Resume for Forza Horizon 6: To disable Forza Horizon 6 from using Quick Resume, highlight the game box art anywhere in the console experience (Home, My Games & Apps, Pins, etc) and then press the Menu button, then go to Manage game and add-ons > Quick Resume settings > Disable Quick Resume. Ensure you are online when ‘quitting’ the game. Give your saved time to sync to the cloud before powering off or switching devices. Do not force quit the game during save screens. Do not power off the device during gameplay. Always "Quit" (console) or "Exit to desktop" (PC) once you've finished your play session, ensuring the save icon is not visible when you’re closing the game. Before turning off your console, shutting down your PC, or force-closing the Steam app, give your devices or clients at least a few minutes to ensure your latest progress has been synchronized with the cloud. This will reduce the risk of progress reversions as you switch between different platforms. XBOX Series X|S consoles, Steam, and the XBOX app on PC all include game save indicators that confirm your progress has been synced. You can read more about the bug in the official support document here. Forza Horizon 6 is currently available on PC (Steam and the Microsoft Store), Xbox Series X|S, and Game Pass. The game is also coming to PlayStation 5 later this year.
    • If only Windows would have a toggle switch labeled "Get the latest updates as soon as possible" inside Windows Update settings... But nah, let's hide the new stuff inside a controlled feature rollout, even if the user is explicitly asking for the new stuff as soon as possible. Awesome idea!
    • After watching the Apple event earlier this week it is quite the contrast. Apple is going back and tweaking the code to make things more efficient in many areas of MacOS. Windows is boosting your electric build to hide their issues.
  • 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
      502
    2. 2
      PsYcHoKiLLa
      199
    3. 3
      +Edouard
      157
    4. 4
      Steven P.
      84
    5. 5
      ATLien_0
      74
  • Tell a friend

    Love Neowin? Tell a friend!