Using PowerCLI to connect to the Admin console using RDP

Here is a easy trick to connect to your Windows VM, using RDP. Essentially we are using the Get-VMGuest cmdlet to fetch VM’s IP Address. And then using the RDP client to connect to the VM’s admin console in full screen mode.

function Start-VMRdp() {
param (
[string]$Name = $(Read-Host -prompt "Enter the VM Name"),
[string]$Network = $(Read-Host -prompt "Enter the Network")

)
$IP=((Get-VMGuest $VM).IPAddress|Where-Object {$_ -match $Network}); mstsc /v:$IP /admin /f
}

Now I know you can always use the vSphere client and look up the IP and connect to it using the RDP client. However what if you have a multihomed VM, you need find the IP address and remember it. This trivial function helps to easy that pain.

The function is very easy to use, just connect to your vCenter Server. And call the function as mentioned below. I have saved this function to my $profile so it gets loaded everytime I start PowerShell.

Start-VMRdp -Name win7-vm1 -Network '192.168.141.*'

BTW, for this to work you need to have VMware tools installed on your VM.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s