I'm setting up an Azure DevOps self hosted pipeline agent. We have some legacy cloud services, so we need the "old" Azure powershell module that targets the service management API. We also obviously use Azure Resource Manager, so either the AzureRM or the new Az module is also required.
We currently have the Azure module version 5.3.0 and AzureRM module version 6.13.1 being installed using the following commands:
Install-Module -Name Azure -RequiredVersion 5.3.0 -AllowClobber -Scope AllUsers -Force
Install-Module -Name AzureRM -RequiredVersion 6.13.1 -AllowClobber -Scope AllUsers -Force
The problem we're encountering is that, depending on the order these modules are imported, we will get script failures. If, for example, the order of import is Azure followed by AzureRM, we get the following error:
Import-Module : The following error occurred while loading the extended type data file: Error in TypeData "Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContextContainer": The TypeConverter was ignored because it already occurs. Error in TypeData "Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContextContainer": The member SerializationDepth is already present. Error in TypeData "Microsoft.Azure.Commands.Common.Authentication.ProtectedFileTokenCache": The member PropertySerializationSet is already present. Error in TypeData "Microsoft.Azure.Commands.Common.Authentication.ProtectedFileTokenCache": The member SerializationMethod is already present. Error in TypeData "Microsoft.Azure.Commands.Common.Authentication.AuthenticationStoreTokenCache": The member PropertySerializationSet is already present. Error in TypeData "Microsoft.Azure.Commands.Common.Authentication.AuthenticationStoreTokenCache": The member SerializationMethod is already present. Error in TypeData "Microsoft.Azure.Commands.Profile.Models.PSAzureContext": The member SerializationDepth is already present. Error in TypeData "Microsoft.Azure.Commands.Profile.Models.PSAzureProfile": The member SerializationDepth is already present. At C:\Program Files\WindowsPowerShell\Modules\AzureRm\6.13.1\AzureRM.psm1:81 char:1 + Import-Module AzureRM.Profile -RequiredVersion 5.8.2 -Global + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Import-Module], RuntimeException + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand
You can see this in the following screen shot:
But if import AzureRm first, followed by Azure, it appears to work fine:
The problem is, we don't control the order of the imports when using existing pipeline tasks built by Microsoft and others. We're getting failures deploying our cloud services due to the fact the cloud service deployment task built by MS happens to import Azure first.
Lastly, I tried simply not installing the old Azure module, hoping that AzureRM "came with" what it would need to handle some service management API tasks, but it does not. If I try do a deployment without the Azure module installed, we get the error:
Certificate based authentication is not supported. Azure PowerShell module is not found.
So it appears the legacy module is required, and yet it conflicts.