Reading Time: < 1 minute
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.
1 2 3 4 5 6 7 8 |
# 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.
1 2 |
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.
1 2 |
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!