About Me

My photo
HANUMANGARH, RAJASTHAN, India
Showing posts with label DNS Name. Show all posts
Showing posts with label DNS Name. Show all posts

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

    }

}

Tuesday, 26 July 2022

Fetch DNS Name along with IP Address

 $Servers = Get-Content -Path "C:\users\$env:username\desktop\servers.txt"

$Array = @()

 

Foreach($Server in $Servers)

{

    $DNSCheck = $null

    $Server = $Server.trim()

 

    $DNSCheck = ([System.Net.Dns]::GetHostByName(("$Server")))

 

    $Object = New-Object PSObject -Property ([ordered]@{ 

      

                "Server name"             = $Server

                "FQDN"                    = $DNSCheck.hostname

                "IP Address"              = $DNSCheck.AddressList[0]

 

    })

   

    # Add object to our array

    $Array += $Object

 

}

$Array

$Array | Export-Csv -Path C:\users\$env:username\desktop\results.csv -NoTypeInformation

Extract Disk Info from Remote host

 # Define the remote hostname or IP address $remoteHost = Get-Content "C:\temp\RemoteServer.txt" # Define the output CSV file path...