Configure DHCP with Powershell

I’m constantly rebuilding my home test labs from scratch. I actually have two isolated home test labs running on Hyper-V and VMware.

Before my test home lab is running I need to install and configure my Active Directory, Router and Microsoft Deployment Tool servers. So I have a lots of clicks. I try to do most of this stuff in Powershell. Here is my script to automatically configure DHCP with Powershell.

$DNSDomain="testlab.local"
$DNSServerIP="10.0.0.10"
$DHCPServerIP="10.0.0.10"
$StartRange="10.0.0.150"
$EndRange="10.0.0.200"
$Subnet="255.255.255.0"
$Router="10.0.0.138"

Install-WindowsFeature -Name 'DHCP' –IncludeManagementTools
cmd.exe /c "netsh dhcp add securitygroups"
Restart-service dhcpserver
Add-DhcpServerInDC -DnsName $Env:COMPUTERNAME
Set-ItemProperty –Path registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ServerManager\Roles\12 –Name ConfigurationState –Value 2
Add-DhcpServerV4Scope -Name "DHCP Scope" -StartRange $StartRange -EndRange $EndRange -SubnetMask $Subnet
Set-DhcpServerV4OptionValue -DnsDomain $DNSDomain -DnsServer $DNSServerIP -Router $Router
Set-DhcpServerv4Scope -ScopeId $DHCPServerIP -LeaseDuration 1.00:00:00

Download: Configure DHCP with Powershell

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s