Configure DHCP with Powershell

22 Shares

As you will hear about in my upcoming podcast Ask Eric I’m constantly rebuilding my home labs from scratch. Make sure to submit your Podcast question now to get an Amazon Gift Card.

I actually have three isolated labs running on XenServer, VMware and Hyper-V3.

Before my Automation Framework is running I need to install and configure my Active Directory, Router and Microsoft Deployment Tool servers. So too save a lots of clicks I try to do most of this stuff in Powershell. Here’s my script to automatically configure DHCP with Powershell.

Configure DHCP with Powershell

DHCP After Configuration

You can read more my various Powershell scripts in the following posts:

22 Shares

Automation Framework Community Edition

The fastest way to build your lab environment.

Virtual Expo

Friday 30th of September 2022

6 thoughts on “Configure DHCP with Powershell”

  1. Hi,
    I worked on a migration to DHCP 2012 (failover)
    I used the pipeline.
    It goes like this: import-CSV …. | set-dhcpserverv40….
    It is super easy and worked fine for scores, options, reservations, …
    I had only one problem with this approach. You can’t put 2 DNS for instance.
    I had to create a separate script for that.
    All the information can be found at

    http://blogs.technet.com/b/teamdhcp/archive/2012/07/15/bringing-powershell-to-dhcp-server.aspx?pi47623=2

    Hope this help
    Regards

    Reply
  2. I’am having trouble trying to figure out an interactive script for this scenario. Help in anyway possible. Much appreciated.

    Scenario: Over the next six months your company is going to be adding four new branch offices. Each of these offices will have 10-12 desktop computers and a dedicated file server. The computers and the server will be drop shipped to the new locations. You have hired a new tech who will be installing the equipment in the branch offices. He has never worked with DHCP, so you are going to build him an interactive script to install and configure DHCP on the server. He will log into the server, open PowerShell, and execute the script which will walk him through the process. He will have documentation for each site including the starting and ending IP address for the appropriate scope. The DCHP script will need to include the following options:

    Scope name – to be supplied by the tech (will also be the site name)
    Starting address – to be supplied by the tech
    Ending address – to be supplied by the tech
    Subnet mask -255.255.255.0
    Domain name – (site name same as the scope name).example.local
    DNS Server – 172.16.0.12 (at the main office)
    Router – to be supplied by the tech
    The script will also need to activate the DHCP server in the dc1.yakima.example.local domain controller.

    Reply
  3. Adam (or anyone else),

    Here’s a quick hint, and keep in mind that you’ll want to really use functions that validate the input, but quick and dirty would be this:

    example:
    $Variable = Read-Host -Prompt ”

    Reply

Leave a Comment