0

I am using PowerShell for some work in Azure. I am trying to run this code, but I get an error saying:

'Unable to find type [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider].'

$context = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile.DefaultContext

I tried everything to fix it I searched for the DLL file I need, but to no avail. I tried to add the type using this command:

add-type -assemblyname Microsoft.Azure.Common

But that also gives an error. I am also using the latest version of PowerShell:

Name Value
PSVersion 5.1.18362.1171
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.18362.1171
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Please help!

Vasudev Gupta
  • 89
  • 3
  • 7
  • Could be a duplicate of [Missing AzureRmProfileProvider module](https://stackoverflow.com/questions/49681706/missing-azurermprofileprovider-module) – Theo May 08 '21 at 12:02
  • The error was caused because it was using Azure CLI. If Azure powershell is used it causes no error. They are different. – Vasudev Gupta May 09 '21 at 14:50

1 Answers1

0

The error was caused because it was using Azure CLI. If Azure powershell is used it causes no error. They are different.

I am not sure if you have solved this issue, but you should have some misunderstandings about them, if you run this line in the PowerShell locally, this issue has nothing to do with Azure CLI, Azure CLI is another type of command written by python.

To solve the issue, you just need to import the module Az.Accounts via Import-Module -Name Az.Accounts -Force, make sure you have installed Az powershell module first, then login with Connect-AzAccount, normally it will import the Az.Accounts module automatically meanwhile for you, no need to do it manually. So if you find it works fine now without import anything, actually it imports it for you automatically.

Sample:

Connect-AzAccount
$context = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile.DefaultContext

enter image description here

Manual way:

enter image description here

Joy Wang
  • 39,905
  • 3
  • 30
  • 54
  • Thanks a lot, I had been struggling with it for a long time. When I ran it through pipeline, it wasn't giving me an error, most likely because it had that module installed in it. I knew I had to install some module, but couldn't figure out which module to install, as there was no information on it. And I spent all my time trying to figure out which GAC assembly to install. – Vasudev Gupta May 11 '21 at 16:03