So im pretty new to powershell and i have multiple questions on how to write scripts using it but right now my main issue is that i want to be able to ping all of the computers on my network and take the names of the computers that ping back and put them into an array so that i can push updates to the computers that are on the network just using one array containing the current computers on the network. here is what i am working with right now.
foreach ($c in $204computernames)
{if(test-connection -computername $c.name -count 1 -quiet)
{write-host $c.name
}
}
currently this string of code runs a foreach loop so that $c(the computers) run against $204computernames(the known computers on the network)then it tests the positive connections through the if statement and finally at the end it outputs the names of the computers that are on the network. Now the problem im understanding from this is when i use a foreach loop that it will run against all of the known computers and as each computer is put through the loop it is replaced by the preceding one, but i want each and every one that comes back on the network to be stored in an array. Is there a way that i can do this with the current format or is there a certain way that i can tweak what i have so that i can get the output i want?
$computernames.name(as an argument toTest-Connection) a typo?