We help IT Professionals succeed at work.

Powershell Test connection then mstsc

Hi All,

I have this line of code that test connection for servers:

PS G:\> Test-Connection -ComputerName  sdindc01, sraddc01, sdendc01, senadc01, sewcdc01, solidc01 -Count 1 | selec
t address

Open in new window


if the ping is successful I then want to Mstsc in to the servers, I've tried:
$t=Test-Connection -ComputerName  sdindc01, sraddc01, sdendc01, senadc01, sewcdc01, solidc01 -Count 1 | selec
t address
$t | % {mstsc /v:$_}

Open in new window


However this does not work. please help
Comment
Watch Question

Senior Network Consultant / Engineer
Commented:
Try this:
$t=Test-Connection -ComputerName  sdindc01, sraddc01, sdendc01, senadc01, sewcdc01, solidc01 -Count 1 | select -ExpandProperty address
$t | % {mstsc /v:$_}

Open in new window

Jeremy WeisingerSenior Network Consultant / Engineer

Commented:
Glad to help. :)