PowerShell for Windows Admins

Sep 20 2011   3:25PM GMT

PowerShell and DHCP: 1 – servers



Posted by: Richard Siddaway
Tags:
PowerShell 3
Windows 8

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

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: