locked
How do i get this script to report ipaddress ? RRS feed

  • Question

  • I am using this script below - how do I get the ipaddress reporting back?

    Get-Content C:\temp\servers.csv |
         ForEach-Object{
              if(Test-Connection $_ -Count 1 -quiet){
                   "$_ Good"
              }else{
                   "$_ Bad"
              }
         }

    Wednesday, July 25, 2018 3:25 PM

All replies

  • Remove "-Quiet" and parse the results.

    Always check help before asking a trivial question.

    help Test-Connection -online


    \_(ツ)_/


    • Edited by jrv Wednesday, July 25, 2018 3:29 PM
    Wednesday, July 25, 2018 3:29 PM
  • Get-Content C:\temp\servers.csv | ForEach-Object{
      $ping = Test-Connection $_ -Count 1 -ErrorAction SilentlyContinue
    
      if ($ping -ne $null) {
        $ping.IPV4Address
      }else{
        Write-Host 'Bad Machine'
      }
    }


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''


    • Edited by clayman2 Wednesday, July 25, 2018 3:30 PM typo
    Wednesday, July 25, 2018 3:29 PM
  • Also

    [System.Net.DNS]::GetHostAddresses('alpha') | select IPAddressToString


    \_(ツ)_/

    Wednesday, July 25, 2018 3:32 PM