We have a number of Virtual Machines hosted in Azure that are used for development or testing purposes. Since we don’t need them online 24⁄7, we have some of them scheduled to turn on during office hours. Other we manually control when we need that particular configuration.
This Virtual Machines have dynamic IP Addresses, so we don’t know where to connect to once the VM has been turned on.
Rather than having to open up the Azure portal I have a powershell script for each machine that will find out the current public IP Address and then open up RDP to connect to it.
Login-AzureRmAccount
$resourceGroup = "Your-resourceGroup"
$vmName = "your-vm-name"
$nicName ="vm-name-nic"
Get-AzureRmVM -ResourceGroupName $resourceGroup -Name $vmName
$vmpublicip = Get-AzureRmPublicIpAddress -ResourceGroupName $resourceGroup -Name $nicName
$publicIp = $vmpublicip.IpAddress
mstsc /v:"$publicIp"