0
votes

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!

1
Could be a duplicate of Missing AzureRmProfileProvider moduleTheo
The error was caused because it was using Azure CLI. If Azure powershell is used it causes no error. They are different.Vasudev Gupta

1 Answers

0
votes

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