Recently I’ve migrated a bunch of Virtual Box Virtual Machines to Azure as detailed here. These VM’s are in Resource Groups with a Network Security Group associated that restricts access to them for RDP based on a source TCPIP address. All good practice. However from a usability perspective, when I want to use these VM’s, I’m not always in the same location, and rarely on a connection with a static IP address.
This post details a simple little script that;
- Has a couple of variables associated with a Resource Group, Network Security Group, Virtual Machine Name and an RDP Configuration File associated with the VM
- Gets the public IP Address of the machine I’m running the script from
- Prompts for Authentication to Azure, and retrieves the NSG associated with the Resource Group
- Compares the Source IP Address in the ‘RDP’ Inbound Rule to my current IP Address. If they aren’t a match it updates the Source IP Address to be my current public IP Address
- Starts the Virtual Machine configured at the start of the script
- Launches Remote Desktop using the RDP Configuration file
Here’s the raw script. Update lines 2-8 for your environment and away you go. Simple but useful as is often the way.