Answers for "powershell system.net.dns gethostaddresses error"

0

powershell system.net.dns gethostaddresses error

$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
Posted by: Guest on August-25-2020
0

powershell system.net.dns gethostaddresses error

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
		}
	}
Posted by: Guest on August-25-2020

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language