Share via

Azure Function App - "ERROR: The term 'Connect-AzAccount' is not recognized"

Thomas Murnane 81 Reputation points
2023-04-27T15:27:51.6033333+00:00

I have a function app that has a queue trigger to run an Invoke-AzRunCommand on an Azure VM that was working just fine a couple of weeks ago. It is not used that often but when trying today, I'm seeing the following in my logs: "The Function app may be missing a module containing the 'Disable-AzContextAutosave' command definition."

Per a thread I found searching for the error - I added the following 'Az.Accounts' to the requirements.psd1 file like so - I have no idea about versioning:

@{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. 
    # To use the Az module in your function app, please uncomment the line below.
    'Az'          = '9.*'
    'Az.Accounts' = '2.*'
}

I did get this to work when running from 'Code + Test' but when trying to run via web app - it fails with the above error.

I didn't even know where it was being called and then found it in the profiles.ps1 file. I'm assuming this is needed since I'm using the System Assigned identity:

if ($env:MSI_SECRET) {
    Disable-AzContextAutosave -Scope Process | Out-Null
    Connect-AzAccount -Identity
}

How do I get passed this error?

In the Configuration the Runtime Version is ~4 with no other options in the drop-down:
User's image

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
{count} vote

1 answer

Sort by: Most helpful
  1. Thomas Murnane 81 Reputation points
    2023-04-27T19:37:22.28+00:00

    So I went out to check out the versions of each of these modules and noticed that they were both updated a few days ago - hard coding these to the previous versions worked:

    @{
        # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. 
        # To use the Az module in your function app, please uncomment the line below.
        'Az'          = '9.5.0'
        'Az.Accounts' = '2.12.1'
    }
    
    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.