Search code examples
powershell

Check if computers from file are online


I'm trying to check if computer from file computers.txt are online or not. I'm using below commend but i would like to see computer name next to true or false resolution of this. It its possible to add it?

Test-Connection -BufferSize 32 -Count 1 -ComputerName (Get-Content C:\Temp\computers.txt) -Quiet |
Out-GridView

Solution

  • The alternative to Theo's answer, using Select-Object syntax:

    Get-Content C:\Temp\computers.txt |
    select @{n="Computer";e={$_}}, @{n="IsOnline";e={Test-Connection -BufferSize 32 -Count 1 -ComputerName $_ -Quiet}} |
    Out-GridView
    

    Pros: Faster, and works even with older PowerShell versions that do not support [pscustomobject]

    Cons: Clumsy syntax