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

Advertisements

4 responses

  1. Ravindra Pawar

    i have tested and it is giving me some error, please send me currect one.

    June 14, 2014 at 4:31 am

    • Hi Ravindra, what’s the error? Can you copy it here?

      June 14, 2014 at 6:54 am

  2. Pingback: Using Powershell to get list of all Domain Controllers with static IPs and email it as CSV file attachment | Sam's Corner

  3. Pingback: Listing all domain Controllers with Static IP’s – Vikingtech Site

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s