Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

test-connection help..

$
0
0

Hi I'm trying to write a simple script that will pull from DNS a specific set of records then go on to ping the hostnames retrieved.   

 

$hostname=Get-DnsServerResourceRecord -ZoneName dmz.root -Computername DNSSERVER -RRType A | ?{$_.hostname -like "*XYZ*" -or $_.hostname -like "*zyx*"} | select @{name="ComputerName";expression={$_.hostname}} 

foreach ($computername in $hostname)

{(Test-Connection -computername $computername -BufferSize 16 -count 1)}

 

The error I get is 

"Testing connection to computer '@{ComputerName=acomputer}' failed: A non-recoverable error occurred during a database lookup"

I guess this is because "computername=acomputer" is passed along for each object, if I look at the contents of $hostname it all looks correct only the computer names exist, but if I look at whats being passed into $computername I see "@{ComputerName=acomputer}" .  I thought by creating the custom property "computername" only that would be passed along.  How do I get round this with test-connection.  

How does $hostname only contain a single object yet when I look at whats passed on to $computername it has the original records format  @{ComputerName=acomputer}  ?

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles