4

I'm trying to upgrade from AzureRM to the new Az module for powershell. We still have multiple usages of "legacy" service management API resources, such as classic Azure Cloud Services, and these (as far as I know) still require the use of the old Azure powershell module.

I've uninstalled all AzureRM modules and then installed the new Az modules. But doing this appears to break the legacy Azure module. It seems that there is a dependency between the Azure module and AzureRM. Running any service management command, such as "Get-AzureService" results in the following:

PS C:\WINDOWS\system32> Get-AzureService
Get-AzureService : Exception has been thrown by the target of an invocation.
At line:1 char:1
+ Get-AzureService
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzureService], TargetInvocationException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.HostedServices.GetAzureServiceCommand

I tried updating to the latest Azure powershell module (Update-Module Azure). This appears to also install AzureRM.profile.

AzureRm.profile dependency

Since that module can't be installed/used at the same time as the Az module, I'm at a loss as how to continue.

Az and AzureRM conflict

Is it the case that there is no way to use the legacy service management APIs via powershell if you also want to use the new Az module?

RMD
  • 3,421
  • 7
  • 39
  • 85
  • [import-module](https://social.technet.microsoft.com/Forums/windowsserver/en-US/b1b574bf-f55c-40c2-bc2f-4b0db95c5f40/how-to-work-with-multiple-versions-of-powershell-modules-my-hell) and specify the version maybe. [start-process](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process) or [invoke-command](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/invoke-command) or if you cannot import both at the same time [azure-powershell](https://hub.docker.com/r/azuresdk/azure-powershell/) – lloyd May 30 '19 at 15:09
  • I recommend you to migrate the resources from classic to ARM, then use the new `Az` module uniformly, see https://learn.microsoft.com/en-us/azure/virtual-machines/windows/migration-classic-resource-manager-overview – Joy Wang May 31 '19 at 02:23
  • 1
    Classic cloud services cannot be migrated to ARM as far as I know. – RMD May 31 '19 at 12:31

1 Answers1

1

The Az module has a compatibility mode to help you use existing scripts while you update to the new syntax. Try to run Enable-AzureRmAlias cmdlet enables a compatibility mode before you want to run AzureRM commands in a new Az session.

enter image description here

You could get more details from migrating existing scripts to Az

Nancy
  • 26,865
  • 3
  • 18
  • 34
  • I'm not trying to execute AzureRM commands. I'm trying to execute service manament API commands, such as Get-AzureService. I will try this, though, and see if it fixes the issue. – RMD May 31 '19 at 12:32
  • This did not resolve the issue. I uninstalled AzureRM and enabled the alias support. Running Get-AzureService still results in the same error. – RMD May 31 '19 at 13:10
  • I might have jumped the gun here. I force reinstalled the Az module and now it's breaking differently. :) – RMD May 31 '19 at 16:13
  • 1
    This worked. I had to reinstall the Az module twice, but I not longer get any errors after I enabled the aliases. Thank you! – RMD May 31 '19 at 18:51
  • 1
    To add to this, you must make sure that you've got the Azure module 5.3.0+ install, and NO other older version. Once that's installed, force install the Az module again. – RMD May 31 '19 at 19:00
  • Azure module 5.3.1 still depends on Azure.Storage module, which depends on AzureRM.Profile. Did not work for us. – viskin Jan 06 '21 at 19:02