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!

  On 12/01/2015 at 14:51, RedReddington said:

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.

  On 12/01/2015 at 09:41, Roger H. said:

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

    • Basically, they can hire someone with less skill for a lower wage, for example from India, and use AI to bring that employees output up to the level of someone more experienced and expensive. It’s a broad cost-cutting strategy, and plenty of companies are already doing it. With AI involved, the employee just needs to check that the AI's results aren’t complete junk. They don’t actually have to know how to produce the work themselves. You just get one high level employee to triple check who does. The workflow looks like this: AI generates the content, a low-skilled worker filters out anything clearly broken or wrong, and a high-skilled worker gives it a final pass. Instead of hiring a full team of experts, companies can rely on a few at the top while AI and cheaper labour handle the bulk of the process.
    • Aah, always the evil terrorist group. Why not just the Russians, they're worse than any terrorist organisation.
    • LG Electronics sees profit dip but boosts shareholder returns by Paul Hill LG Electronics (LGE) has reported consolidated sales of 20.74 trillion Korean Won (approximately $15.14 billion USD) and an operating profit of 639.4 billion Korean Won (approximately $466.75 million USD) for the second quarter of 2025. The firm saw both its revenue and operating profits decline year-over-year due to external factors such as US tariff policies, ongoing geopolitical issues in the Middle East, and a slowdown in consumer spending. While the company has faced challenges, the company is aiming for what it called qualitative growth by strengthening its subscription services, direct online sales, and business-to-business (B2B) segments. Key areas of growth for LGE include automotive electronics, heating, ventilation, and air conditioning (HVAC) systems, and the webOS platform. The US tariffs are a major headache for companies around the world, given the size of the market there and President Trump's demands for bringing manufacturing to the States. To combat the rising US tariffs, LGE is trying to optimize global production and refine its market-specific approaches for premium and mass-market products. While the company’s profits dipped, it announced an interim dividend of 500 Korean Won (approximately $0.37 USD) per share for both common and preferred, with another payout later in the year that should take the total for 2025 to at least 1,000 Korean Won (approximately $0.73 USD). You must be holding the stock on August 8, 2025, to get the payout on August 22, 2025. The firm also said it will cancel 761,427 common treasury shares on July 31, 2025, making shares more scarce which could increase the value of remaining shares for investors. In terms of LGE’s various business divisions, things were mixed. Its Home Appliance Solution (HS) business achieved year-over-year sales growth, maintaining profitability, thanks to a dual strategy for premium and volume segments and growth in online sales and subscriptions. Its Media Entertainment Solution (MS) business experienced declines in sales and operating profits with the latter turning negative due to market uncertainties and stiff competition. Its Vehicle Solution (VS) business showed growth in sales and operating profit thanks to increased orders from European automotive makers. Finally, its Eco Solution (ES) business saw domestic sales increase, but overseas sales growth was limited due to US tariffs. This led to a slight year-over-year drop in operating profit due to higher costs. Image via Depositphotos.com
    • "Microsoft plans to remove the MSN feed..." Yaaay, finally the horrible dumpster fire of badly translated tabloid trash is going away! Good riddance! "...and replace it with Copilot Discover..." Oh ffs...
    • Similar to how Nvidia stopped caring about the consumer market a while ago and now just pays lip service to it because it prints money.
  • Recent Achievements

    • Week One Done
      Itbob513626 earned a badge
      Week One Done
    • One Month Later
      Itbob513626 earned a badge
      One Month Later
    • Rookie
      EdwardFranciscoVilla went up a rank
      Rookie
    • Week One Done
      MoJo624 earned a badge
      Week One Done
    • Collaborator
      aeganwn earned a badge
      Collaborator
  • Popular Contributors

    1. 1
      +primortal
      618
    2. 2
      ATLien_0
      243
    3. 3
      Xenon
      159
    4. 4
      Michael Scrip
      126
    5. 5
      +FloatingFatMan
      122
  • Tell a friend

    Love Neowin? Tell a friend!