1

I'm using Azure Function 2.0 with Powershell and getting below error while installing Powershell modules.

Is there any way to get rid of this error. In general, we don't need admin rights to install NuGet/dependency.

I also tried with another way to put all Powershell modules under Modules folder enter image description here

Still, function is not able to find Cosmos DB modules

enter image description here

2 Answers 2

5

If the modules you want to use are on the PowerShell Gallery, the easiest way to use them from PowerShell Functions is to take advantage of the Managed Dependencies feature. All you need to do is to make sure you have the feature enabled in the host.json:

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

and your module is mentioned in the requirements.psd1:

@{
    Az = '2.*'
    SqlServer = '21.1.18147'
}

Azure Functions will automatically make sure these modules are installed and available to your functions. No need to copy files.

Please also note that AzureRM modules are not supported on Azure Functions v2.0, use Az instead.

Sign up to request clarification or add additional context in comments.

1 Comment

Let me try.. will see if it will solve my purpose. Thanks
2

You cannot simply call Import-Module Az.Profile like on your local machine where you have previously installed Az.Profile from that site. But you have to copy all files from that locally installed package into specific folder inside of your Function App in Azure.

1.Install Az.Profile in local and go to its folder to get all the content in it.

2.Go to your function KUDU. Click CMD>site>wwwroot>yourFunctionName then create a directory called modules.

3.Simply drag-and-drop all files from your local powershell module location to your Azure Function App folder create above(modules).

4.Include Az.Profile PowerShell module in run.ps1 file like that example below:

Import-Module "D:\home\site\wwwroot\HttpTrigger1\modules\Az.Profile.psd1"

5.Install Az.Resources and CosmosDB module as above steps.

6.Run Get-CosmosDbOffer -Context $cosmosDbContext and you will get the following snapshot.

enter image description here

For more details, you could refer to this tutorial and this one.

4 Comments

Are you using Function version 2.0?
Yes, I use the default version 2.0.
Yes, it's working. I was copying the complete PowerShell module folder under modules folder
Copying all .psd1 and .dll files under modules folders maybe create conflict. for now, I'm okay to continue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.