Powershell script to check out gateway configuration of remote computers

Hey guys,
I had a small task today to check out the configured gateway for some servers part of my Active Directory Domain Services. The servers have two network interfaces (frontend/backend). I wanted to see if a specific IP is configured on one of the interfaces from any of the servers included within an OU, so I came out with the following script:

$computers = Get-ADComputer -SearchBase ‘OU=Servers,DC=ppscu,DC=com’ -Filter ‘*’ | Select -Exp Name

foreach ($comp in $computers)

     $result = Invoke-Command -ComputerName $comp -ScriptBlock {
        $interfaces = Get-WmiObject Win32_NetworkAdapterConfiguration | ? { $_.IPEnabled }
        foreach ($int in $interfaces)
            $cmp = ($env:computername)
            $gateway = $int.DefaultIPGateway
            $ipaddress = $int.IPAddress        
            if ($gateway -like “”)
                Write-Host “$cmp has gateway on $ipaddress” -BackgroundColor Red
                Write-Host “$cmp does not have the specified gateway on $ipaddress, gateway is: $gateway ” -BackgroundColor white -ForegroundColor Black


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