Posts tagged “Get domain controllers with Static IP addresses

Using Powershell to list all domain controllers with Static IP addresses


4 May 2016 update:

This updated script does not require ActiveDirectory Powershell module, and returns an array object , each record has 2 properties: DCName, and DCStaticIPv4. This makes it easier to further process as input for other scripts.

Expect this script to error out if not running in an AD domain environment (like in a workgroup)

Sample output looks like:

Get-DCs1

 


DomainControllerThe following script lists all domain controllers in the current domain that have a static IPv4 address:

# Script to list domain controllers with static IP addresses
# Sam Boutros
# 6/13/2014
#

write-output “Listing all domain controllers with static IPs:”
$DCs = Get-ADDomainController -Filter *
foreach ($DC in $DCs.Hostname)
{
$ints = Get-WmiObject -ComputerName $DC -Query “select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE and DHCPEnabled=FALSE”
ForEach ($int in $ints.IPAddress)
{
if ($int.Contains(“.”)) # This is IPv4, not IPv6
{write-output “DC Name: $DC, Static IPv4: $int”}
}
}

IPv4

 


Similar script to list all domain computers with Static IPs:

# Script to list domain computers with static IP addresses
# Sam Boutros
# 6/13/2014
#
write-output “Listing all domain computers with static IPs:”
$PCs = Get-ADComputer -Filter * | Sort-Object -Property Name
foreach ($PC in $PCs.DNSHostname)
{
$ints = Get-WmiObject -ComputerName $PC -ErrorAction SilentlyContinue -Query “select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE and DHCPEnabled=FALSE”
ForEach ($int in $ints.IPAddress)
{
if ($int.Contains(“.”)) # This is IPv4, not IPv6
{write-output “PC Name: $PC, Static IPv4: $int”}
}
}

PCs