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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$DNSDomain="ctxlab.local" $DNSServerIP="192.168.1.10" $DHCPServerIP="192.168.1.10" $StartRange="192.168.1.150" $EndRange="192.168.1.200" $Subnet="255.255.255.0" $Router="192.168.1.1" 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 |
You can read more my various Powershell scripts in the following posts:
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
Thanks for sharing, bumped into the 2nd DNS as well.
Multiple DNS entries can be applied with -Force
Set-DhcpServerv4OptionValue -OptionId 6 -Value $DNSServerIP1 , $DNSServerIP2 , $DNSServerIP3 -Force
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.
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 ”
There should have been text in between the quotes, but I’m sure you get the point.