PowerShell | DHCP Check Enabled
<#
Summary:
Get list of servers from AD
Loop through servers and test access
Use WMI to get NIC settings in relation to specific IP
Check if that NIC with IP Scheme has DHCP value enabled
Export results to file
Author: Scott Head
Date: 05/09/2022
Version: 1.0
#>
# Get all Enabled Computers from IT
$Server_Computers=Get-ADComputer -Properties * -Filter {(Enabled -eq $True) -and (Operatingsystem -Like "Windows Server*")} | Select -ExpandProperty Name
#Array of Computers
$Array=@()
# Test network connection
Foreach($Computer in $Server_Computers){
$Checker=Test-Connection $Computer -Count 1 -Quiet
If($Checker){$Array+=$Computer}
$Computer
}
Foreach($Comp in $Array){
$Result=Get-WMIObject -ComputerName $Comp Win32_NetworkAdapterConfiguration | where{$_.IPAddress -like "172.*"} | select -ExpandProperty DHCPEnabled
"$Comp | $Result" | Tee-Object C:\temp\DHCP.txt -Append
}