The Function app may be missing a module containing the 'Set-AzStorageAccount' command definition. If this command belongs to a module available on the PowerShell Gallery, add a reference to this module to requirements.psd1.

Tati, Vinod 5 Reputation points
2023-11-02T02:21:54.8966667+00:00

I am getting the error below
Although i have included the below in my requirements.psd1

 'Az' = '10.*'
    'Az.Storage' = '5.*'
    'Az.Accounts' = '2.*'
}

The Function app may be missing a module containing the 'Set-AzStorageAccount' command definition. If this command belongs to a module available on the PowerShell Gallery, add a reference to this module to requirements.psd1. Make sure this module is compatible with PowerShell 7. For more details, see https://aka.ms/functions-powershell-managed-dependency. If the module is installed but you are still getting this error, try to import the module explicitly by invoking Import-Module just before the command that produces the error: this will not fix the issue but will expose the root cause.
I ma trying to use command below

Set-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName -EnableSftp $true

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,930 questions
Windows for business | Windows Server | User experience | PowerShell
{count} vote

1 answer

Sort by: Most helpful
  1. navba-MSFT 27,550 Reputation points Microsoft Employee Moderator
    2023-11-02T06:24:15.3966667+00:00

    @Tati, Vinod Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    I understand you are encountering an error while trying to use the Set-AzStorageAccount command in their Function app. The error message suggests that a module containing the command definition is missing, and you should add a reference to this module in the requirements.psd1 file.

    Plan 1:
    Please ensure that you are using the below version for Function and powershell:**
    **
    User's image

    User's image

    User's image

    Plan 2:
    If you are using an older version of Powershell, you need to upgrade it to Powershell 7.2 by following this article:
     https://github.com/Azure/azure-functions-powershell-worker/wiki/Upgrading-your-Azure-Function-Apps-to-run-on-PowerShell-7.2

    Plan 3:
    Please hard code the specific versions and test:

    @{
    	'Az.Storage' = '5.10.0'
        'Az.Accounts' = '2.13.0'
    }
    

    Plan 4:
    I also recommended that you don't import all of the Az module. So please remove 'Az' = '10.*'as it will increase performance on cold starts. I feel there might be an issue with the dependencies causing the module to not load.
    **
    Plan 5:**
    Functions lets you leverage PowerShell gallery for managing dependencies. With dependency management enabled, the requirements.psd1 file is used to automatically download required modules. You enable this behavior by setting the managedDependency property to true in the root of the host.json file, as in the following example:

    {
      "managedDependency": {
              "enabled": true
           }
    }
    

    After following the above plan , please restart the function app and test again.

    If this doesn't help. Please let me know. I would be happy to assist you further.

    **
    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.


Your answer

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