This article covers information about AzureNSGRuleForRemoteLocation commands on my custom module HannelsToolBox. This includes a video demonstration going over how to use the commands and the effect is has to Azure resources. The module can be found in the PowerShell Galley.

AzureNSGRuleForRemoteLocation

The 2 commands covered in this article are Add-AzureNSGRuleForRemoteLocation and Remove-AzureNSGRuleForRemoteLocation. Both commands make changes to the NSG(s) attached to the VM they are ran against.

The Add command identifies your current IP and adds a rule in virtual machine’s NSG(s) to allow connection from current IP. the Remove command removes custom rule (AllowRuleForRemoteLocation) from NSG(s) tied to a VM

Video:

Prerequisite, install Module and log into Azure Account;

 

  1. Install-Module -Name HannelsToolBox
  2. Login-AzureRmAccount

 

Steps in the above video covers;

  • Confirm RDP port (3389) is not reachable
  • Run Add command to add a rule on NSG to allow connection from the public IP you are coming from.

Example:

Add-AzureNSGRuleForRemoteLocation -SubscriptionId 1d6737e7-4f6c-4e3c-8cd4-996b6f003d0e -rgName DDemo
-vmName DDemo-VM2 -OS Windows
  • Confirm RDP port (3389) is now reachable
  • Look at the RDP rule that was added to NSG to allow traffic from current IP
  • Run Remove command searches and removes the rule on NSG to allow connection from the public IP you are coming from.

Example:

Remove-AzureNSGRuleForRemoteLocation -SubscriptionId 1d6737e7-4f6c-4e3c-8cd4-996b6f003d0e -rgName DDemo
-vmName DDemo-VM2
  • Confirm the RDP rule has been remove from NSG
  • Confirm RDP port (3389) is not reachable
  • Review other option in the help file for commands

Linked to module in the PowerShell Gallery

https://www.powershellgallery.com/packages/HannelsToolBox/

Linked to code for module in GitHub

https://github.com/hhazeley/HannelsToolBox

HannelsToolBox Series

http://hazelnest.com/blog/blog/tag/hannelstoolbox