DHCP is very important technology in any organisational infrastructure. Many administrators finds very difficultly in managing DHCP and DHCP scopes in large farm.
There are many commands for managing DHCP which are used by administrators and networks guys, but still there is no willing results which can be retrieved from this commands.
Like "netsh dhcp server show scope"
We need DHCP cmdlet to be available in order to manage DHCP. By default, the DHCP module is not loaded in Powershell. We need to install and import the DHCP module before we can use it.
It is available from Windows server 2012 and windows server 2012R2 onwards.
Before you use any DHCP cmdlets, you need to import DHCP module
Import-Module DhcpServer
Note - You have to install DHCP role with management tools, to get this module on system. It can be also installed by PS command for Adding Windows Featured
Add-WindowsFeature -Name DHCP -IncludeManagementTools
The following new DHP PowerShell cmdlets have been introduced in Windows Server 2012 R2:
Add-DhcpServerSecurityGroup : Adds security groups to a DHCP server.
Add-DhcpServerv4MulticastExclusionRange: Adds a range of addresses to exclude from a multicast scope.
Add-DhcpServerv4MulticastScope: Adds a multicast scope on the DHCP server.
Get-DhcpServerDnsCredential: Gets an account that the DHCP Server service uses to register or deregister client records on a DNS server.
Get-DhcpServerv4MulticastExclusionRange: Retrieves the exclusion range for a specified multicast scope.
Get-DhcpServerv4MulticastLease: Retrieves multicast leases for a specified scope name.
Get-DhcpServerv4MulticastScope: Gets multicast scope objects.
Get-DhcpServerv4MulticastScopeStatistics: Gets multicast scope statistics.
Get-DhcpServerv4SuperscopeStatistics: Returns statistics for superscopes.
Remove-DhcpServerDnsCredential: Removes the credential that the DHCP Server service uses to register or deregister client records on a DNS server.
Remove-DhcpServerv4MulticastExclusionRange: Removes a range of addresses previously excluded from a multicast scope.
Remove-DhcpServerv4MulticastLease: Removes one or more multicast scope leases for a specified multicast scope or IP address.
Remove-DhcpServerv4MulticastScope: Removes multicast scopes.
Rename-DhcpServerv4Superscope: Renames a superscope.
Repair-DhcpServerv4IPRecord: Reconciles inconsistent lease records in the DHCP database.
Set-DhcpServerDnsCredential: Sets credentials that the DHCP Server service uses to register or deregister client records on a DNS server.
Set-DhcpServerv4MulticastScope: Modifies the properties of a multicast scope.
There are many things which you can achieve using this cmdlets
@@@@ Get list of all DHCP scopes on a DHCP server
Get-DhcpServerv4Scope -ComputerName Server1 | fl
Get-DhcpServerv4Scope -ComputerName Server1,Server2 | Select-Object Scopeid,Name,State,StartRanage, EndRange
# Will give you specific details on DHCP scope details from remote server named Server1 and Server2
@@@@ Adding new scope using ADD-DhcpServerv4Scope
Add-DHCPServerv4Scope -Name Test_Scope -StartRange 192.168.100.50 -EndRange 192.168.100.100 -SubnetMask 255.255.255.0
@@@@ Count DHCP Server in environment
(Get-Command -Module DHCPServer).count
@@@@ To authorize a new DHCP server in Active Directory Domain
Add-DhcpServerInDC -DnsName Script.Chef.com -IPAddress 10.9.0.78
@@@@ Configuring multiple scope in DHCP server
$Scopes = Get-Content -Path C:\Scopes.csv #Reading Scopes from txt file
$DnsServer=10.9.0.7,10.990.8,10.9.0.0
$Domain=Shanky.chef.com
$Router=10.9.0.1
Foreach($Scope in $Scopes)
{
Set-DHCPServerv4OptionValue -ComputerName DhcpSrv1 -ScopeId $Scope -DnsServer $DnsServer -DnsDomain $Domain -Router $Router
}
@@@@ Create a reservation for a client with the IP-address 10.44.1.88:
Get-DhcpServerv4Lease -ComputerName DhcpSvr1 -IPAddress 10.44.1.88 | Add-DhcpServerv4Reservation -ComputerName DhcpSvr1
You can perform a mass reservation of IP-addresses for computers listed in a CSV file. To do it, create a text file in the following format:
ScopeId,IPAddress,Name,ClientId,Description
10.44.1.0,10.44.1.88,Client1,b3-ac-5c-fd-9e-6f,Reservation DhcpSvr1
10.44.1.0,10.44.1.89,Client2,b3-ac-5c-fd-9e-3f,Reservation DhcpSvr1
Save this file as c:\dhcp\DHCP_Reservations.csv and run the next command that imports the data from the CSV file and creates reservations for the clients:
Import-Csv –Path c:\dhcp\DHCP_Reservations.csv | Add-DhcpServerv4Reservation -ComputerName DhcpSvr2
@@@@ You can get DHCP server statistics (the number of scopes and reservations, the percentage of used addresses, etc.).
Get-DhcpServerv4Statistics -ComputerName DhcpSvr1
No comments:
Post a Comment