PowerShell 3 and DHCP 2: scopes

In this post http://msmvps.com/blogs/richardsiddaway/archive/2011/09/20/powershell-and-dhcp-1-servers.aspx

I showed how we could discover DHCP server information

Scopes can be discovered

Get-DhcpServerv4Scope -ComputerName server02  -ScopeId 10.10.54.0

Now how do we create a scope?

We use Add-DhcpServerv4Scope. Now shouldn’t that have been New-DhcpServerv4Scope?

Never the less this is how it works

Add-DhcpServerv4Scope -ComputerName server02 -Name TestScope 
-StartRange 192.168.100.1 -EndRange 192.168.100.200
-Description "Scope for testing" -Type DHCP
-State Active -SubnetMask 255.255.255.0
-LeaseDuration (New-TimeSpan -Days 1)

Type can be Dhcp,Bootp or Both

State can be Active or InActive

This creates and activates the scope

To inactivate a scope

Set-DhcpServerv4Scope -ComputerName server02
-ScopeId 192.168.100.0
-State Inactive

To reactivate

Set-DhcpServerv4Scope -ComputerName server02
-ScopeId 192.168.100.0
-State Active

To create a reservation

Add-DhcpServerv4Reservation -ComputerName server02
-ScopeId 192.168.100.0 -IPAddress 192.168.100.190
-ClientId 00-01-02-03-04-05 -Name Test57 
-Description "Exclusion for test device"

The ClientId is the MAC address (this one is made up)

To view the scopes reservations

Get-DhcpServerv4Reservation -ComputerName server02 -ScopeId 192.168.100.0

To remove a reservation

Remove-DhcpServerv4Reservation -ComputerName server02
-ScopeId 192.168.100.0 -ClientId 00-01-02-03-04-05

Leave a Reply