Home
%3CLINGO-SUB%20id%3D%22lingo-sub-744461%22%20slang%3D%22en-US%22%3EHow%20to%20Manage%20DHCP%20using%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-744461%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EMost%20organizations%20are%20already%20going%20to%20have%20DHCP%20deployed%20on%20their%20servers.%20If%20you%20have%20a%20new%20server%20on%20which%20you%20want%20to%20deploy%20DHCP%2C%20just%20run%20the%20PowerShell%20command%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3EInstall-WindowsFeature%20DHCP%20-IncludeManagementTools%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%3EOnce%20you%E2%80%99ve%20installed%20a%20DHCP%20server%20on%20a%20computer%20running%20Windows%20Server%2C%20you%20need%20to%20authorize%20that%20server%20in%20Active%20Directory.%20If%20you%20don%E2%80%99t%20do%20this%2C%20then%20the%20DHCP%20server%20won%E2%80%99t%20be%20able%20to%20lease%20addresses%20to%20clients.%20You%E2%80%99ll%20need%20to%20run%20the%20command%20with%20an%20account%20that%20has%20Enterprise%20Admin%20privileges%20in%20the%20forest%2C%20or%20is%20a%20Domain%20Admin%20account%20in%20the%20forest%20root%20domain.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EYou%20can%20do%20this%20by%20running%20the%20PowerShell%20command%20(where%20you%20substitute%20in%20the%20appropriate%20FQDN%20and%20IP%20address%20of%20the%20DHCP%20server%20that%20you%20want%20to%20authorize).%20Note%20that%20you%20don%E2%80%99t%20need%20to%20run%20this%20on%20the%20DHCP%20server%2C%20you%20can%20have%20someone%20else%20with%20the%20appropriate%20privileges%20run%20it%20on%20a%20DC.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3EAdd-DhcpServerInDC%20-DNSName%20dhcp-srv.contoso.internal%20-IPAddress%20172.16.0.50%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%3EYou%20can%20view%20a%20list%20of%20DHCP%20server%20that%20are%20authorized%20in%20AD%20by%20running%20the%20following%20command%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3EGet-DhcpServerInDC%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20882px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F122682i2BEEACE60C5110D6%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Image-1.png%22%20title%3D%22Image-1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ENow%20that%20the%20DHCP%20server%20is%20authorized%2C%20you%E2%80%99ll%20need%20to%20add%20a%20scope.%20You%20can%20do%20this%20with%20the%20Add-DhcpServerV4Scope%20cmdlet.%20For%20example%2C%20to%20create%20a%20scope%20named%20Subnet-Alpha%20that%20includes%20the%20range%20172.16.0.100%20through%20172.16.0.200%20with%20a%20%2F24%20subnet%20mask%2C%20run%20the%20command%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3EAdd-DhcpServerV4Scope%20-name%20%E2%80%9CSubnet-Alpha%E2%80%9D%20-StartRange%20172.16.0.100%20-Endrange%20172.16.0.200%20-SubnetMask%20255.255.255.0%20-State%20Active%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%3EYou%20can%20check%20which%20scopes%20are%20present%20on%20a%20server%20using%20the%20Get-DHCPServerV4Scope%20cmdlet.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20882px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F122683i3C4523EFA393441E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Image-2.png%22%20title%3D%22Image-2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EYou%E2%80%99ll%20need%20to%20add%20both%20a%20default%20gateway%20and%20a%20DNS%20server%20address%20to%20that%20scope%2C%20which%20you%20can%20do%20with%20the%20Set-DhcpServerv4OptionValue%20cmdlet.%20For%20example%2C%20to%20set%20the%20DNS%20server%20to%20172.16.0.10%20and%20the%20default%20gateway%20to%20172.16.0.1%20for%20the%20Subnet-Alpha%20scope%2C%20which%20has%20the%20scope%20ID%20172.16.0.100%20(or%20the%20first%20address%20in%20the%20range%20for%20the%20scope)%20run%20the%20command%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CPRE%3ESet-DhcpServerV4OptionValue%20-ComputerName%20dhcp-srv.contoso.internal%20-ScopeID%20172.16.0.100%20-DNSServer%20172.16.0.10%20-Router%20172.16.0.1%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%3EYou%20can%20then%20check%20that%20the%20options%20have%20been%20set%20correctly%20using%20the%20Get-DhcpServerV4OptionValue%20cmdlet%20with%20the%20ScopeID%20parameter.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20882px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F122684iDD198D713F3C5028%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Image-3.png%22%20title%3D%22Image-3.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EYou%20can%20view%20DHCP%20leases%20from%20a%20specific%20scope%20using%20the%20Get-DhcpServerv4Lease%20cmdlet%20with%20the%20ScopeID%20parameter.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20882px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F122685i6D5E51B737481082%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Image-4.png%22%20title%3D%22Image-4.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EYou%20can%20use%20the%20Add-DhcpServerv4Reservation%20cmdlet%20to%20convert%20a%20lease%20to%20a%20reservation.%20To%20do%20this%2C%20you%20need%20the%20MAC%20address%2C%20which%20is%20represented%20by%20the%20client%20ID%20in%20the%20output%20of%20Get-DHCPServerV4Lease%20cmdlet.%20For%20example%2C%20to%20create%20a%20reservation%20for%20the%20computer%20with%20the%20MAC%20address%2000-16-5d-56-9e-04%20for%20the%20IP%20address%20172.16.0.45%20in%20the%20scope%20ID%20172.16.0.0%2C%20run%20the%20command%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CPRE%3EAdd-DhcpServerv4Reservation%20-ScopeID%20172.16.0.0%20-IPaddress%20172.16.0.45%20-ClientID%20%E2%80%9C00-15-5d-56-9e-04%E2%80%9D%20-Description%20%E2%80%9CReservation%20for%20MEL-SVR2%E2%80%9D%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%3EYou%20can%20validate%20which%20reservations%20are%20present%20within%20a%20scope%20using%20the%20Get-DhcpServerV4Reservation%20cmdlet.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20882px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F122686i139C7E040AD783AD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Image-5.png%22%20title%3D%22Image-5.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EIf%20you%20wish%20to%20locate%20several%20free%20IP%20addresses%20within%20a%20scope%20that%20are%20not%20being%20leased%2C%20you%20can%20use%20the%20Get-DhcpServerv4FreeIPAddress%20cmdlet%20with%20the%20NumAddress%20parameters.%20For%20example%2C%20to%20locate%20five%20IP%20addresses%20that%20aren%E2%80%99t%20being%20used%20in%20the%20172.16.0.0%20scope%2C%20run%20the%20command%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CPRE%3EGet-DhcpServerv4FreeIPAddress%20-ScopeID%20172.16.0.0%20-NumAddress%205%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20882px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F122687iC4A3E74AB74E5BF6%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Image-6.png%22%20title%3D%22Image-6.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EYou%20can%20learn%20more%20about%20the%20PowerShell%20cmdlets%20that%20you%20use%20to%20manage%20DHCP%20in%20the%20following%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fdhcpserver%2F%3FWT.mc_id%3Dblog-ITOPSTALK-orthomas%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Edocs.microsoft%3C%2FA%3Earticle.%20%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-744461%22%20slang%3D%22en-US%22%3E%3CP%3ELearn%20how%20to%20create%20and%20configure%20DHCP%20scopes%2C%20manage%20leases%20and%20reservations%20using%20PowerShell.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-744461%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDHCP%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20Server%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Most organizations are already going to have DHCP deployed on their servers. If you have a new server on which you want to deploy DHCP, just run the PowerShell command:

 

Install-WindowsFeature DHCP -IncludeManagementTools

Once you’ve installed a DHCP server on a computer running Windows Server, you need to authorize that server in Active Directory. If you don’t do this, then the DHCP server won’t be able to lease addresses to clients. You’ll need to run the command with an account that has Enterprise Admin privileges in the forest, or is a Domain Admin account in the forest root domain.

 

You can do this by running the PowerShell command (where you substitute in the appropriate FQDN and IP address of the DHCP server that you want to authorize). Note that you don’t need to run this on the DHCP server, you can have someone else with the appropriate privileges run it on a DC.

 

Add-DhcpServerInDC -DNSName dhcp-srv.contoso.internal -IPAddress 172.16.0.50

You can view a list of DHCP server that are authorized in AD by running the following command:

 

Get-DhcpServerInDC

Image-1.png

Now that the DHCP server is authorized, you’ll need to add a scope. You can do this with the Add-DhcpServerV4Scope cmdlet. For example, to create a scope named Subnet-Alpha that includes the range 172.16.0.100 through 172.16.0.200 with a /24 subnet mask, run the command:

 

Add-DhcpServerV4Scope -name “Subnet-Alpha” -StartRange 172.16.0.100 -Endrange 172.16.0.200 -SubnetMask 255.255.255.0 -State Active

You can check which scopes are present on a server using the Get-DHCPServerV4Scope cmdlet.

Image-2.png

You’ll need to add both a default gateway and a DNS server address to that scope, which you can do with the Set-DhcpServerv4OptionValue cmdlet. For example, to set the DNS server to 172.16.0.10 and the default gateway to 172.16.0.1 for the Subnet-Alpha scope, which has the scope ID 172.16.0.100 (or the first address in the range for the scope) run the command:

Set-DhcpServerV4OptionValue -ComputerName dhcp-srv.contoso.internal -ScopeID 172.16.0.100 -DNSServer 172.16.0.10 -Router 172.16.0.1

You can then check that the options have been set correctly using the Get-DhcpServerV4OptionValue cmdlet with the ScopeID parameter.

 

Image-3.png

You can view DHCP leases from a specific scope using the Get-DhcpServerv4Lease cmdlet with the ScopeID parameter.

 

Image-4.png

You can use the Add-DhcpServerv4Reservation cmdlet to convert a lease to a reservation. To do this, you need the MAC address, which is represented by the client ID in the output of Get-DHCPServerV4Lease cmdlet. For example, to create a reservation for the computer with the MAC address 00-16-5d-56-9e-04 for the IP address 172.16.0.45 in the scope ID 172.16.0.0, run the command:

Add-DhcpServerv4Reservation -ScopeID 172.16.0.0 -IPaddress 172.16.0.45 -ClientID “00-15-5d-56-9e-04” -Description “Reservation for MEL-SVR2”

You can validate which reservations are present within a scope using the Get-DhcpServerV4Reservation cmdlet.

Image-5.png

If you wish to locate several free IP addresses within a scope that are not being leased, you can use the Get-DhcpServerv4FreeIPAddress cmdlet with the NumAddress parameters. For example, to locate five IP addresses that aren’t being used in the 172.16.0.0 scope, run the command:

Get-DhcpServerv4FreeIPAddress -ScopeID 172.16.0.0 -NumAddress 5

Image-6.png

You can learn more about the PowerShell cmdlets that you use to manage DHCP in the following docs.microsoft article.