macospowershellazure-rmaz

Azure RM module doesn't work on MACOSX Catalina


I'm trying to use AzureRM and AZ module on Powershell core on OSXCatalina, but, when I try to use the cmdlet Login-AzureRmAccount or Login-AzAccount. I receive the errors bellow. I'm currently using the Powershell version 7

Login-AzureRmAccount: The term 'Login-AzureRmAccount' 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.

Login-AzAccount: The 'Login-AzAccount' command was found in the module 'Az.Accounts', but the module could not be loaded. For more information, run 'Import-Module Az.Accounts'.


Solution

  • This is not a Powershell code issue, which is what we are here to help with. Yours is an environment issue, thus it really should be moved to SuperUser or StackExchange.

    Yet, since you are here, and this is environmental because you may have not set it up correctly/completely, How to set this up and use it is fully documented on MS Docs, MSDN, and many other locations all over the web. A quick search, say using 'AzureRM osx' would have shown you things like below. these:

    PowerShell, Azure and macOS? Absolutely!

    With Azure CLI on macOS you can do interesting things like provisioning new VMs or get a status overview on them. But Azure CLI is not PowerShell and so it lacks some features I really appreciate.

    There are several steps to do in order to be able to manage Azure via PowerShell on your Mac:

    Install PowerShell
    Install .NET Core
    Install the AzureRm.NetCore.Preview module
    
    brew update
    brew install openssl
    ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
    ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
    

    After that you can download the official installer of .NET Core for macOS. After installation you need to initialize some code. You can do that by using the following commands:

    mkdir hwapp
    cd hwapp
    dotnet new
    dotnet restore
    dotnet run
    
    Install-Package -Name AzureRM.NetCore.Preview -Source https://www.powershellgallery.com/api/v2 -ProviderName NuGet -ExcludeVersion -Destination /usr/local/microsoft/powershell/6.0.0-alpha.11/Modules
    
    get-module -listAvailable
    

    AzureRM PowerShell Mac OS X

    Everything can be resolved by installing AzureRM from here:

    Install-Package -Name AzureRM.NetCore.Preview -Source https://www.powershellgallery.com/api/v2/ -ProviderName NuGet -ExcludeVersion -Destination $home/powershell/modules
    
    Import-Module $home/powershell/modules/AzureRM.Profile.NetCore.Preview
    Import-Module $home/powershell/modules/AzureRM.Resources.NetCore.Preview
    Import-Module $home/powershell/modules/AzureRM.NetCore.Preview
    Login-AzureRmAccount
    

    PS. Import-Module would have to be rerun every time PowerShell is restarted.

    Powershell and Azure on MacOS

    Well, unless you put it in your profile.