Ping Script help

Good morning, I was trying to write a script that will get computer names and then would ping them to check if they are online.


#This script will get a list of names for all the computers in that room
$comps=Get-ADComputer -filter ‘name -like “Buildingroomnumber”’ | Select-Object -property name
foreach ($comp in $comps){
ping $comp}

When I run the above, I get:
Ping request could not find host @{name=COMPNAME} Please check the name and try again. I thought it might just be ping, so i tried the Test-Connection cmdlet, but I get the same sort of problem.

How do I get a list of the computer names that will pipe into ping or test-connection so that I can see if the computers are online?

Duplicate of https://powershell.org/forums/topic/ping-script-help-2/