I've been using these lines of code:
$204computernames = Get-ADComputer -searchbase $sb -filter * | ?{$_.name -like "ptfg*-061*"} | select name
$onlineComputers = $204computernames |Where-Object { Test-Connection $_.name -Count 1 -Quiet }
to grab all of my computers on my network and put them into a variable so I can push all of my documents, updates, etc to them so that I dont have to go to each computer individually to get the files I want where I want. When I take the variable and put it into a line of code like this
Test-Connection $onlineComputers
I get errors like this:
Test-Connection : Testing connection to computer '@{name=PTFGW-0613618TN}' failed: A non-recoverable error occurred during a database lookup
At line:1 char:1
+ Test-Connection $onlineComputers
I'm assuming after extensive testing in different codes that there is a problem with the way my variable stores its values. Does anyone know how I can fix this issue?
Test-Connection $onlineComputerstoTest-Connection $onlineComputers.Name?| Select nameit creates a custom object with anameproperty for each computer and not just a list of computer names. You need to pass only the names toTest-Connection- adding.nameimplicitly loops through all the objects pulling out the value of thenameproperty. So, the answer to your question is that it depends on the type of information you are passing as to whether or not you need to do this (or something similar). You can always check the type of information by doing something like this:$onlineComputers.GetType()| foreach name.