Managing DHCP with PowerShell Part 2

In Part 1 I exported existing DHCP scopes from an existing server. In Part 2 I’ll use PowerShell to import the scopes on to a new DHCP Server and also share some real world considerations.

Pre-requisites

  • PowerShell Remoting and RSAT tools as discussed in Part 1
  • DHCP is required to be authorised and you will need an account with Enterprise Admins to complete this task
  • Move the exported file (from Part1) to the new DHCP server
Real World Tip

You may have group policies that are configured to explicitly block highly privileged accounts from logging on such as the Enterprise Admins which will stop you authorising DHCP

If this is the case, move the server to the Default computers OU and run GPUpdate /Force to update the policies, in some cases it was easier to just restart the server once it was moved to the OU. Once you have authorised it don’t forget to move it back and also highlight this to your security teams as they may get alerts regarding the activity 🙂

  1. Open PowerShell ISE or VSCode and use PSRemoting to connect to your new DHCP Server.

# Connect to DHCP Server
$DHCPServer = DHCP2.domain.local
New-PSsession -ComputerName $DHCPServer

<#
Author: <Author Name>
Created: <Date>
Purpose: This script imports DHCP scopes
#>

# Script Variables
# DHCP Server Name
$DHCPServerName = ‘DHCP2.domain.local’
# Path and File name of the DHCP Import
$DHCPFile = C:\Temp\ScopeIDsExport.xml
# Backup Path
$Backup = C:\Temp\Backups

Import-DhcpServer -ComputerName $DHCPServerName -File $DHCPFile -BackupPath $Backup

In Part 3 I’ll highlight creating the failover relationship using hot standby mode

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s