Last week, I needed to quickly find out all the Authorized DHCP Servers in the AD Forest. Fortunately, the following Powershell cmdlet saved me a lot of time and I wanted to share it with you.
First of all, you need to make sure that the following module is loaded in order to use the cmdlet that meets our needs.
# Check if the ActiveDirectory module is Loaded
Get-Module -Name ActiveDirectory
# Check if the ActiveDirectory module is available
Get-Module -Name ActiveDirectory -ListAvailable
# Import the ActiveDirectory module if it is not loaded
Import-Module -Name ActiveDirectory
Query AD for Authorized DHCP Servers, make sure you use the forest tree root domain.
Get-ADObject -SearchBase "cn=configuration,dc=contoso,dc=com" -Filter
"objectclass -eq 'dhcpclass' -AND Name -ne 'dhcproot'" | select name
In case you want to export the results into a text file use the following syntax.
Get-ADObject -SearchBase "cn=configuration,dc=contoso,dc=com" -Filter
"objectclass -eq 'dhcpclass' -AND Name -ne 'dhcproot'" | select name | Out-File c:\typeyourpathhere
Thanks for reading my blog!
Feel free to drop your comment or question below.