Saltar al contenido

Powershell system.net.dns gethostaddresses ejemplo de código de error

Ejemplo 1: error de powershell system.net.dns gethostaddresses

cls

import-module activedirectory

$w = "L2-Windows Servers"
$ComputerList = Get-ADComputer -Filter * 

foreach ($Computer in $ComputerList) {
	$IP = $Null
	$ErrorActionPreference = "silentlycontinue"
	$IP = [System.Net.Dns]::GetHostAddresses($Computer.DNSHostName)
	$ErrorActionPreference = "continue"
	If ($IP -ne $Null) {
		Write-Output ("add filter filterlist=" + $w + " srcaddr=any dstaddr=" + $IP + "description=" + $Computer.Name)  | Out-File "c:dailyimport.nsh" -width 120 -Append
		}
	If ($IP -eq $Null) {
		Write-Output ($Computer.DNSHostName + "Could Not Be Resolved") | Out-File "c:Error.Log" -width 120 -Append
		}
	}

Ejemplo 2: error de powershell system.net.dns gethostaddresses

$computers= gc C:ListvOfDevices.txt
$list = @()
foreach ($computername in $computers)
{
	If(Test-Connection $computername -Quiet)
	{
		write-host "$computername - $IP - UP" -ForegroundColor GREEN
		Try
		{	
			$IP = [System.Net.Dns]::GetHostEntry($computername).AddressList | %{$_.IPAddressToString}
			$IP | %{$HostName = [System.Net.Dns]::GetHostEntry($_).HostName}
		}
		Catch
		{
			write-error "Can't resolve IP or hostname from dns."
		}


		$compStatus = New-Object PSObject -Property @{            
        					OrgName  = $computername 
						Active   = $true               
        					HostName = $HostName    
						IP       = $IP             
		}
		$list += $compStatus 

	}
	else
	{
		write-host "$computername - $IP - DOWN" -ForegroundColor RED
		$IP = $null
		$HostName = $null
		$compStatus = New-Object PSObject -Property @{            
        					OrgName  = $computername 
						Active   = $false
        					HostName = $null
						IP       = $null
		}
		$list += $compStatus 

	}
}
$list
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)


Tags :

Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *