Using Az module with Visual Studio Azure resource group projects

I recently uninstalled the AzureRM PowerShell module to upgrade to the AZ module. In doing so I can no longer deploy using the generated PowerShell script of Resource Group projects in Visual Studio. In this post I will explain how to upgrade your scripts to use the new AZ module.

If you attempt to run the script as is, you will get the following error.

The term 'New-AzureRmResourceGroup' is not recognized
as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.

Below is a mapping of the old and new Cmdlet names as they appear in the Deploy-AzureResourceGroup.ps1:

Old Name

New Name

Publish-AzureRmVMDscConfiguration

Publish-AzVMDscConfiguration

Get-AzureRmContext

Get-AzContext

Get-AzureRmStorageAccount

Get-AzStorageAccount

New-AzureRmResourceGroup

New-AzResourceGroup

New-AzureRmStorageAccount

New-AzStorageAccount

New-AzureStorageContainer

New-AzStorageContainer

Set-AzureStorageBlobContent

Set-AzStorageBlobContent

New-AzureStorageContainerSASToken

New-AzStorageContainerSASToken

Test-AzureRmResourceGroupDeployment

Test-AzResourceGroupDeployment

New-AzureRmResourceGroupDeployment

New-AzResourceGroupDeployment

Notice it is not just a global find and replace of “AzureRM” to “Az”. Some of the Cmdlets use the noun “Azure” instead of “AzureRM” for example “New-AzureStorageContainer”.

You can make all the mentioned substitutions or simply use this GitHubGist instead

Comments (3) -

  • Andy

    5/1/2019 10:50:46 PM | Reply

    This is a useful reminder to rename AzureRM references when you switch to using the new Az module, unfortunately it doesn't appear to resolve the problem; presumably as Visual Studio is referencing the older modules in its own code too.  I'm using VS Enterprise 2017 and although some of the errors changed when I updated Deploy-AzureResourceGroup.ps1, it still doesn't work.

  • Istvan

    3/27/2020 5:34:55 PM | Reply

    You can add this command to line 28 in the original script:
    Enable-AzureRmAlias

    This way you don't need to find and replace all the old commands, and you don't need to have the AzureRM module installed.

    • Robert E Coker

      11/21/2020 8:16:50 PM | Reply

      This fixed the problem after much searching for an answer.

Add comment

Loading