About Me

My photo
HANUMANGARH, RAJASTHAN, India

Monday, 19 December 2022

Hostname to IP address

 $location = Read-Host "CSV Path: "

$Names = Import-Csv -Path $location


foreach($n in $Names)

{

    try {

        $Computer = [system.net.dns]::resolve($n.NAME) | Select HostName,AddressList 

        $IP = ($Computer.AddressList).IPAddressToString

        New-Object PSObject -Property @{IPAddress=$IP; Name=$Computer.HostName} | Export-Csv \\filepath\Working.csv -NoTypeInformation -Append

    } catch {

        Write-Host "$($n.NAME) is unreachable."

        Write-Output $n | Export-Csv \\Filepath\Unreachable.csv -Append -Encoding ASCII

    }

}

No comments:

Post a Comment

Export contact from Justdial

  Extract Data From JustDial using Selenium Let us see how to extract data from Justdial using Selenium and Python. Justdial is a company th...