For reasons that aren’t necessarily relevant, I wanted to use Remote Desktop to visit a list of servers1. I tried doing this:

foreach ($S in "server01", "server02, "server03") { 
    mstsc /f /V:$S
}

This works….but it immediately starts rdp sessions to each of the servers. This is fine in this example, where there are only 3 servers, but in real life I’ve got a list of twenty or so and I don’t really want to open 20-odd rdp sessions at once.

What I did instead to force it do the rdp’s sequentially was this:

foreach ($S in "server01", "server02, "server03") { 
    mstsc /f /V:$S
    $ThrowAway = read-host "Hit Return"
}

  1. I'd really rather not do this, but I can't find a safe and seen-to-be-safe way of doing what I want to do through PowerShell or any other automated tool