Thanks Scott and Fabio - this works, it's always nice to see different ways of doing things! Now that I see the construct, it all makes sense :).
Thank you, Ray From: listsadmin@lists.myitforum.com [mailto:listsadmin@lists.myitforum.com] On Behalf Of Scott Crawford Sent: Friday, May 06, 2016 3:44 PM To: powersh...@lists.myitforum.com Subject: RE: [powershell] pipe list of DCs, gather name, and ping, return list of DC with corresponding IP Give this a shot: Get-ADDomainController -Filter * | ForEach-Object {Test-Connection $_.Name -Count 1} | select Address, IPV4Address, IPV6Address From: listsadmin@lists.myitforum.com<mailto:listsadmin@lists.myitforum.com> [mailto:listsadmin@lists.myitforum.com] On Behalf Of Raymond Peng Sent: Friday, May 6, 2016 5:02 PM To: powersh...@lists.myitforum.com<mailto:powersh...@lists.myitforum.com> Subject: [powershell] pipe list of DCs, gather name, and ping, return list of DC with corresponding IP Hi All, I'm new to PS and learning as I go. I want to gather a list of domain controllers (instead of dsquery) and select just the names, run a ping test 1 count to return the IP address, have a list of the DC with the IP in an organized way So I gathered a list of DCs and names using the following: Get-ADDomainController -Filter * | Select-Object -Property name | test-connection However when I try to pipe it to test-connection (ping) it errors I know it errors because it doesn't except pipeline input but then Is there a way to make it work onscreen with another command? I think I could export it to a list with just the computernames, get-content, and run test-connection -computername (get-content computers.txt) But this failed as well PS C:\Users\rpeng> $computers = Get-ADDomainController -Filter * | Select-Object -Property name PS C:\Users\rpeng> $computers PS C:\Users\rpeng> Get-ADDomainController -Filter * | select name > C:\data\computers.txt PS C:\Users\rpeng> Get-Content C:\data\computers.txt I feel I need to throw in a foreach command to run this properly Any help is much appreciated, thanks! name ---- WWDCWP01 NYDCWP01 TJDCWP01 WCDCWP01 MQDCWP01 KCCSDC01 KCDCWP02 PVDCWP01 SMDCWP02 NWDCWP01 TMDCWP03 KCDCWP01 SJDCWP01 IRDCWP01 PS C:\Users\rpeng> Test-Connection -ComputerName (Get-Content C:\data\computers.txt) -Count 1 Test-Connection : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. At line:1 char:31 + ... -Connection -ComputerName (Get-Content C:\data\computers.txt) -Count ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Test-Connection], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.TestConnectionCommand Thank you, Ray