Simple Script to Automate Task

Sumner, Khalid 20 Reputation points

Just need a script I can run in Powershell that will take a list of PC hostnames, ping them and return the IP addresses.

A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
3,093 questions
0 comments No comments
{count} votes

Accepted answer
  1. Dillon Silzer 46,211 Reputation points

    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."
        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+([^\.]+).*$"|
          $Computer.Computername = $_.Matches.Groups[1].Value
    $Computers | Export-Csv $FileOut -NotypeInformation
    #$Computers | Out-Gridview

    This will generate:

    User's image

    Cited from

    If this is helpful please accept answer.

0 additional answers

Sort by: Most helpful