locked
powershell test-connection RRS feed

  • Question

  • i have a group of PC

    i want check and list : if online? list name, IP

                                       offline? list name,"offline"

    here what i have now

    Get-Content C:\Users\taxu\Documents\2003.csv | 
    foreach {Test-Connection -ComputerName $_  -Count 1 -Delay 2 -BufferSize 2 -ThrottleLimit 2 -ErrorAction SilentlyContinue}

    thanks

    Saturday, May 18, 2019 12:31 AM

All replies

  • You have to create a custom object and send that or use a computed property.

    Look up both of these things to learn how to use and write PowerShell code.

    There are many examples available.


    \_(ツ)_/

    Saturday, May 18, 2019 1:41 AM
  • Try this:

    foreach ($n in (Get-Content C:\Users\taxu\Documents\2003.csv |)) {
        Try {
            $r = Test-Connection $n -count 1 -ErrorAction Stop
            [PSCustomObject] @{
                Address = $r.Address
                IPV4 = $r.IPV4Address
                IPV6 = $r.IPV6Address
            }
        }
        Catch {
            [PSCustomObject] @{
                Address = $n
                IPV4 = 'offline'
                IPV6 = ''
            }
        }
    }


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Saturday, May 18, 2019 1:53 AM
  • Hi,
    Was your issue resolved? 
    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
    If no, please reply and tell us the current situation in order to provide further help.
    Best Regards,
    Lee

    Just do it.

    Monday, May 20, 2019 2:01 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Monday, June 3, 2019 7:44 AM