Categories

PowerShell and DHCP: 1 – servers

Remember that yesterday I loaded the RSAT tools on to my Windows 8 server instance. This includes a PowerShell module that auto loads – like all Windows 8 modules on the PS module path

Start by looking at the GET commands

Get-Command -Module DhcpServer   get*

Get-DhcpServerAuditLog
Get-DhcpServerDatabase
Get-DhcpServerInDC
Get-DhcpServerSetting
Get-DhcpServerv4Binding
Get-DhcpServerv4Class
Get-DhcpServerv4DnsSetting
Get-DhcpServerv4ExclusionRange
Get-DhcpServerv4Failover
Get-DhcpServerv4Filter
Get-DhcpServerv4FilterList
Get-DhcpServerv4FreeIPAddress
Get-DhcpServerv4Lease
Get-DhcpServerv4OptionDefinition
Get-DhcpServerv4OptionValue
Get-DhcpServerv4Policy
Get-DhcpServerv4PolicyIPRange
Get-DhcpServerv4Reservation
Get-DhcpServerv4Scope
Get-DhcpServerv4ScopeStatistics
Get-DhcpServerv4Statistics
Get-DhcpServerv4Superscope
Get-DhcpServerv6Binding
Get-DhcpServerv6Class
Get-DhcpServerv6DnsSetting
Get-DhcpServerv6ExclusionRange
Get-DhcpServerv6FreeIPAddress
Get-DhcpServerv6Lease
Get-DhcpServerv6OptionDefinition
Get-DhcpServerv6OptionValue
Get-DhcpServerv6Reservation
Get-DhcpServerv6Scope
Get-DhcpServerv6ScopeStatistics
Get-DhcpServerv6StatelessStatis...
Get-DhcpServerv6StatelessStore
Get-DhcpServerv6Statistics
Get-DhcpServerVersion

 

This will keep us busy for a while and we haven’t looked at the other verbs!

Notice we don’t have a get-dhcpserver as such but we do have Get-DhcpServerVersion

 

PS> Get-DhcpServerVersion -ComputerName server02


MajorVersion : 6
MinorVersion : 1

 

PS> Get-WmiObject Win32_OperatingSystem -ComputerName server02 | fl Caption, version


Caption : Microsoft Windows Server 2008 R2 Datacenter
version : 6.1.7601

 

All we need is a bit of a wrapper function to decode the version numbers

 

also server settings

PS> Get-DhcpServerSetting -ComputerName server02


IsDomainJoined            : True
IsAuthorized              : True
DynamicBootp              : True
RestoreStatus             : False
ConflictDetectionAttempts : 0
NpsUnreachableAction      : Full
NapEnabled                : True
ActivatePolicies          :

 

Scopes are fairly important

 

PS> Get-DhcpServerv4Scope -ComputerName server02 | fl *


ScopeId          : 10.10.54.0
SubnetMask       : 255.255.255.0
StartRange       : 10.10.54.246
EndRange         : 10.10.54.250
ActivatePolicies :
Delay            : 0
Description      : Only used for new servers - before a static address is defined
LeaseDuration    : 04:00:00
MaxBootpClients  : 4294967295
Name             : NewServers
NapEnable        : True
NapProfile       :
State            : Active
SuperscopeName   :
Type             : Dhcp
ComputerName     :

 

There are IPv6 equivalent cmdlets as well

 

checking on free addresses

PS> Get-DhcpServerv4FreeIPAddress -ComputerName server02 -ScopeId "10.10.54.0"
10.10.54.246

 

PS> Get-DhcpServerv4FreeIPAddress -ComputerName server02 -ScopeId "10.10.54.0" -NumAddress 10
WARNING: The requested number of free IP addresses could not be found.
10.10.54.246
10.10.54.247
10.10.54.248
10.10.54.249
10.10.54.250

 

PS> Get-DhcpServerv4ScopeStatistics -ScopeId "10.10.54.0" -ComputerName server02 | fl *


ScopeId                       : 10.10.54.0
AddressesFree                 : 5
AddressesFreeOnPartnerServer  :
AddressesFreeOnThisServer     :
AddressesInUse                : 0
AddressesInUseOnPartnerServer :
AddressesInUseOnThisServer    :
PendingOffers                 : 0
PercentageInUse               : 0
ReservedAddress               : 0
SuperscopeName                :
ComputerName                  :

 

and finally

Get-DhcpServerv4Lease -ComputerName server02 -ScopeId "10.10.54.0"

will return the leases

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>