Saturday, October 12, 2013

Windows Server 2012 - DHCP - Part 4 - viewing the configuration (command line)

This post concentrates on the display of DHCP server and scope configuration information using Powershell commands. Some may have already been seen in previous posts.
 
In those previous posts, I've also taken a retrospective look at some of the NETSH commands used to manage DHCP in earlier versions of Windows Server.
 
I'll begin this post with a NETSH command that shows information about the DHCP server itself and then present the equivalent PowerShell commands.
 
 
***
 
This command shows us "DORA" data (essentially number of attempts to contact the server for an IP address), uptime for the server, number of scopes, with some scope information such as the number of used and available addresses, the location of the DHCP database and, finally, some server status information.


PS C:\> netsh dhcp server show all

MIBCounts:
        Discovers = 0.
        Offers = 0.
        Delayed Offers = 0.
        Requests = 0.
        Acks = 0.
        Naks = 0.
        Declines = 0.
        Releases = 0.
        ServerStartTime = Wednesday, October 9, 2013 8:09:18 PM
        Scopes = 2.
        Scopes with Delay configured= 0.
        Subnet = 10.0.0.0.
                No. of Addresses in use = 1.
                No. of free Addresses = 255.
                No. of pending offers = 0.
        Subnet = 192.168.1.0.
                No. of Addresses in use = 1.
                No. of free Addresses = 242.
                No. of pending offers = 0.


Server Database Properties :
        DatabaseName              = dhcp.mdb
        DatabasePath              = C:\Windows\system32\dhcp
        DatabaseBackupPath        = C:\Windows\system32\dhcp\backup
        DatabaseBackupInterval    = 60 mins.
        DatabaseLoggingFlag       = 1
        DatabaseRestoreFlag       = 0
        DatabaseCleanupInterval   = 60 mins.


Server Status:
        Server Attrib - Rogue Authorization Succeeded :TRUE
        Server Attrib - Dynamic BootP Support Enabled :TRUE
        Server Attrib - DHCP Server Part Of DS        :TRUE
        Server Attrib - DHCP Server Bindings Aware    :TRUE
        Server Attrib - Administrative Rights         :TRUE



Now let's see how to see that information using Powershell.
 
But first, I want to show the reader how to obtain a list of Powershell commands - or cmdlets - pertaining to DHCP. Unless blessed with a fabulous memory, most administrators will not be able to remember the hundreds (possibly thousands) of Powershell commands available to manage a Windows 2012 server from the command line (or in a script).
 
So we're just starting to use Powershell (to manage DHCP in this scenario) and we want to see what commands are available. So we enter what follows: 

 
PS C:\> get-command *get-dhcp* | select name

Name
----
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-DhcpServerVersion


Note: there are comparable cmdlets for IPv6 which I have edited out for concision.

So now we have an idea of the available PS cmdlets for DHCP.

Some readers may have noticed that all the DHCP commands begin the same, either:

Get-DHCPServer

or

Get-DHCPServerv4

or, for DHCPv6 (for IPv6):

Get-DHCPServerv6


We then add the element that interests us: Reservation, Scope, etc..

If we want details on a paticular cmdlet, we can use the get-help cmdlet followed by the cmdlet in question:

Get-Help Get-DhcpServerv4Scope

I find the -example parameter especially useful since it goes "straight to the point" with some practical examples:

Get-Help Get-DhcpServerv4Scope -example


Having presented what I believe to be some useful PS tips (in general), let's see some specific cmdlets.

I do not see a "general" or "global" command that displays all the information like  
netsh dhcp server show all.

If we want information on the DHCP database, we use this command:

PS C:\> Get-DhcpServerDatabase

FileName           : C:\Windows\system32\dhcp\dhcp.mdb
BackupPath         : C:\Windows\system32\dhcp\backup
BackupInterval(m)  : 60
CleanupInterval(m) : 60
LoggingEnabled     : True
RestoreFromBackup  : False
IPAddress            DnsName
---------            -------
10.0.0.10            dc-001




Is the DHCP server a member of the domain? Is it activated? This command will tell us:

PS C:\> Get-DhcpServerSetting

IsDomainJoined            : True
IsAuthorized              : True

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



On what network interfaces is DHCP listening for IP address requests?

PS C:\> Get-DhcpServerv4Binding | fl

InterfaceAlias : Ethernet
BindingState   : True
InterfaceGuid  : c53d50cb-d384-4187-9399-ad57a5cac8c5
IPAddress      : 10.1.1.10
SubnetMask     : 255.0.0.0


Note: the " |" followed by "fl" displays the output in list format which I've found preferable to table format when publishing to this blog. The actual formatting commands are "format-list" and "format-table".


How many requests for IP addresses has the server received? How many addresses are used? Available? Use the following command to find out


PS C:\> Get-DhcpServerv4Statistics
 

ServerStartTime           : 10/9/2013 8:09:18 PM
TotalScopes               : 2
ScopesWithDelayConfigured : 0
ScopesWithDelayOffers     :
TotalAddresses            : 499
AddressesInUse            : 2
AddressesAvailable        : 497
PercentageInUse           : 0.4008016
PercentagePendingOffers   : 0
PercentageAvailable       : 99.5992
Discovers                 : 0
Offers                    : 0
PendingOffers             : 0
DelayedOffers             : 0
Requests                  : 0
Acks                      : 0
Naks                      : 0
Declines                  : 0
Releases                  : 0



The following commands provide information on specific scopes, reservations and exclusions.

PS C:\> Get-DhcpServerv4Scope | fl

ScopeId          : 10.0.0.0
Name             : MACH1
Description      :
SuperscopeName   :
SubnetMask       : 255.0.0.0
StartRange       : 10.1.1.0
EndRange         : 10.1.1.255
LeaseDuration    : 8.00:00:00
NapProfile       :
NapEnable        : False
Delay(ms)        : 0
State            : Active
Type             : Dhcp
MaxBootpClients  : 4294967295
ActivatePolicies : True

ScopeId          : 192.168.1.0
Name             : BLDG1
Description      : Building 1 subnet
SuperscopeName   :
SubnetMask       : 255.255.255.0
StartRange       : 192.168.1.1
EndRange         : 192.168.1.254
LeaseDuration    : 8.00:00:00
NapProfile       :
NapEnable        : False
Delay(ms)        : 0
State            : Active
Type             : Dhcp
MaxBootpClients  : 4294967295
ActivatePolicies : True



PS C:\> Get-DhcpServerv4ScopeStatistics | fl

ScopeId                       : 10.0.0.0
AddressesFree                 : 255
AddressesInUse                : 1
PendingOffers                 : 0
ReservedAddress               : 1
PercentageInUse               : 0.390625
SuperscopeName                :
AddressesFreeOnThisServer     :
AddressesFreeOnPartnerServer  :
AddressesInUseOnThisServer    :
AddressesInUseOnPartnerServer :

ScopeId                       : 192.168.1.0
AddressesFree                 : 242
AddressesInUse                : 1
PendingOffers                 : 0
ReservedAddress               : 1
PercentageInUse               : 0.4115226
SuperscopeName                :
AddressesFreeOnThisServer     :
AddressesFreeOnPartnerServer  :
AddressesInUseOnThisServer    :
AddressesInUseOnPartnerServer :



PS C:\> Get-DhcpServerv4Reservation 10.0.0.0 | fl

IPAddress   : 10.1.1.21
ClientId    : 00-0c-29-f8-c0-46
ScopeId     : 10.0.0.0
Name        : PC1.machlinkit.biz
Type        : Both
Description :



PS C:\> Get-DhcpServerv4ExclusionRange 10.0.0.0 | fl

ScopeId    : 10.0.0.0
StartRange : 10.0.0.0
EndRange   : 10.0.0.20

ScopeId    : 10.0.0.0
StartRange : 10.0.0.255
EndRange   : 10.0.0.255


***

As for the additional NETSH equivalents, I'll suggest the reader refer to the following link:

Netsh commands for DHCP

1 comment:

  1. Hi,The Qatari government realise that with such a low indigenous population with company formation in Qatar, workers and businesses from overseas are essential to maintain the country's growth.Thanks....

    ReplyDelete