Tag Archives: RDP

Script Sharing – Remote Desktop Prompts for Multiple Computers

Yes, I still RDP* (occasionally). I am using it less and less, but there are still times when getting inside a system’s GUI is seems necessary. I’m into this Windows PowerShell thing, if you haven’t noticed, so you can rest assured that every time I RDP, I also do my best to figure out how to get the same information using PowerShell. In fact, this often leads to new functions and tools. I just remembered this, but in the earlier days of learning PowerShell I would try and replicate everything I did in the GUI, in PowerShell. If you’re wondering how to learn PowerShell, well then, there you go.

* RDP stands for Remote Desktop Protocol. While you can’t Remote Desktop Protocol into a server, the acronym is often used as a verb: “Hey, RDP over to bigserver1 and let me know if you see the same problem.”

Anyway, let me share a function that I occasionally use. Take a look at the code, and then I’ll briefly discuss it below.

Set-Alias -Name rdp -Value Connect-TMRDP
Set-Alias -Name rdc -Value Connect-TMRDP
Function Connect-TMRDP
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory=$true,Position=1,ValueFromPipeline=$true)]
        [Alias('cn')]
        [string[]]$ComputerName,

        [Parameter(Position=2)]
        [string]$DomainName
    )
    Begin {
    } #End Begin

    Process {
        If ($DomainName) {
            Foreach ($Computer in $ComputerName) {
                If ($DomainName -match '^\.') {
                    mstsc.exe /v "$Computer$DomainName"
                } Else {
                    mstsc.exe /v "$Computer.$DomainName"
                }
            }
        } Else {
            Foreach ($Computer in $ComputerName) {
                mstsc.exe /v $Computer
            }
        }
    }
}

This function allows me the ability to remote desktop into several systems at a time. While it won’t enter user names and passwords for me, it’ll present me the Windows Security logon dialog for each computer name supplied as a value to the -ComputerName parameter. That’s why I wrote it. If you’ve ever used mstsc.exe /v, and got tired of typing that over and over for each machine, now you can save time by typing something like rdp dc01,dc02,web01 and it’ll open a logon dialog for each. The rdp (and rdc) alias is created right before the function — a function I’ve named Connect-TMRDP.

Maybe this helps, may it doesn’t, but it sure speeds up the time it takes me to RDP to several servers at once. I know, I know — the simple fact that I need to RDP to several computers at once makes an even better case for PowerShell. Again, continuing to use RDP on occasion has led to some nice PowerShell tools, and I expect that this will continue.

I did want to mention one final thing about this function. It’s set up to handle the domain name being included in several different ways, if it’s included at all. Each of the examples below will work.

PS> rdp -ComputerName bigserver01
PS> rdp -ComputerName bigserver01.mydomain.com
PS> rdp -ComputerName bigserver01 -DomainName .mydomain.com
PS> rdp -ComputerName bigserver01 -DomainName mydomain.com