Showing posts with label DHCP. Show all posts
Showing posts with label DHCP. Show all posts

Wednesday, February 28, 2018

Get DHCP Server in your Domain

In this post I will show you how to get all DHCP that are used in your Domain.


Show all DHCP Server using netsh
netsh dhcp show server


Show specific DHCP Server using netsh and findstr
netsh dhcp show server | findstr "dhcp01"

Show two DHCP Server using netsh
netsh dhcp show server | findstr "dhcp01 dhcp02"

Results could be exported with >%path%
netsh dhcp show server >C:\admin\dhcp.txt

You can use Powershell using get-adobject and export it with export-csv
$RootDSE = [System.DirectoryServices.DirectoryEntry]([ADSI]"LDAP://RootDSE")
$CfgNC = $RootDSE.Get("configurationNamingContext")
Get-ADObject -SearchBase "$CfgNC" -Filter "objectclass -eq 'dhcpclass' -AND Name -ne 'dhcproot'" | select name | Sort-Object -Property Name | Export-csv "C:\admin\Forest DHCP Servers.csv" -NoType

Or just using Get-DhcpServerInDC
Get-DhcpServerInDC


If you want to filter using Get-DhcpServerInDC you can do it like this
Get-DhcpServerInDC | where dnsname -like *dhcp02*


Thursday, March 30, 2017

Powershell 4 - Get authorized DHCP server

You can use the following command to get all authorized DHCP server:
Get-DhcpServerInDC

The output will be the IP and DNSName of the server.

You can add out-gridview to easy filter or copy it to Excel.
Get-DhcpServerInDC | Out-GridView

If you want to instant filter on name or IP address you can do it this way:
Name:
$DEDHCPs = Get-DhcpServerInDC | where {($_.DNSName –like “DE*”)}
$DEDHCPs

IP:
$ipDHCPs = Get-DhcpServerInDC | where {($_.IPAddress –like “10.15*”)}
$ipDHCPs


You can also write the output directly to a file. Just use export-csv:
Get-DhcpServerInDC | where {($_.IPAddress –like “10.15*”)} | Export-Csv c:\admin\dhcps.csv -NoTypeInformation

or using >c:\admin\dhcps.txt (same output like in PS)

Get-DhcpServerInDC | where {($_.IPAddress –like “10.15*”)} >c:\admin\dhcps.txt