You can try the following:
## Q:\Test\2017\01\21\SO_41785413.ps1
$FileOut = "C:\Users\YOURUSERNAME\Downloads\Computers.csv"
## Ping subnet
$Subnet = "192.168.50."
1..254|ForEach-Object{
Start-Process -WindowStyle Hidden ping.exe -Argumentlist "-n 1 -l 0 -f -i 2 -w 1 -4 $SubNet$_"
}
$Computers =(arp.exe -a | Select-String "$SubNet.*dynam") -replace ' +',','|
ConvertFrom-Csv -Header Computername,IPv4,MAC,x,Vendor|
Select Computername,IPv4,MAC
ForEach ($Computer in $Computers){
nslookup $Computer.IPv4|Select-String -Pattern "^Name:\s+([^\.]+).*$"|
ForEach-Object{
$Computer.Computername = $_.Matches.Groups[1].Value
}
}
$Computers
$Computers | Export-Csv $FileOut -NotypeInformation
#$Computers | Out-Gridview
This will generate:
Cited from https://stackoverflow.com/questions/41785413/use-powershell-to-get-device-names-and-their-ipaddress-on-a-home-network
If this is helpful please accept answer.