Blog | G5 Cyber Security

Block AzureRM PowerShell Module

TL;DR

The AzureRM module is deprecated. This guide shows you how to prevent its use in your environment, ensuring a smooth transition to the Az module and improving cyber security by removing older, potentially vulnerable code.

Steps to Block the AzureRM PowerShell Module

  1. Understand Why You Need to Block AzureRM
  • Check if AzureRM is Installed
  • Run the following command in PowerShell to see if the AzureRM module is present:

    Get-Module -ListAvailable AzureRM

    If it returns information about the module, it’s installed. If it says nothing is found, skip to step 4.

  • Uninstall AzureRM (Recommended)
  • The best approach is to uninstall the module completely:

    Uninstall-Module -Name AzureRM -AllVersions

    You may be prompted for confirmation. Type ‘Y’ and press Enter.

  • Prevent Installation via PowerShellGet
  • To stop users from accidentally installing AzureRM in the future, you can block it in your PowerShellGet settings:

    Set-PSRepository -Name PSGallery -InstallationPolicy Block
  • Option 2: Block a Specific Package – This blocks only AzureRM.
  • Set-PackageSource -Name PSGallery -ProviderName NuGet -Blocked $true
  • Verify the Block
  • After blocking, try to install AzureRM again:

    Install-Module -Name AzureRM

    You should receive an error message indicating that the module is blocked.

  • Update Existing Scripts
  • This is the most important step. Replace all instances of AzureRM cmdlets with their equivalent Az counterparts. For example:

    Microsoft provides detailed migration guides to help with this process.

  • Test Your Updated Scripts
  • Thoroughly test all updated scripts in a non-production environment before deploying them to production. This ensures that the changes haven’t introduced any unexpected issues.

    Exit mobile version