Categorías
Powershell

Resolución de DNS con powershell

Script en powershell para la resolución de IP

$computers= Get-Content C:\sql.txt
$list = @()
Foreach ($computername in $computers)
{
    If(Test-Connection $computername -Quiet)
    {
        write-host "$computername - $IP - OK" -ForegroundColor GREEN
        Try
            {
            $IP = [System.Net.Dns]::GetHostEntry($computername).AddressList | %{$_.IPAddressToString}
            $IP | %{$HostName = [System.Net.Dns]::GetHostEntry($_).HostName}
            }
        Catch
        {
            write-error "NO se puede resolver el IP o DNS."
        }
        $compStatus = New-Object PSObject -Property @{
            Equipo = $computername
            Status = $true
            DNS = $HostName
            IP = $IP
    }
        $list += $compStatus
    }
    Else
    {
        write-host "$computername - $IP - NO_OK" -ForegroundColor RED
        $IP = $null
        $HostName = $null
        $compStatus = New-Object PSObject -Property @{
            Equipo = $computername
            Status = $false
            DNS = $null
            IP = $null
        }
    $list += $compStatus
    }
}
$list | Export-Csv c:\prueba2.csv -NoTypeInformation