Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How do I configure the requirements.psd1 file for custom modules


How do I configure the requirements.psd1 file for custom modules


Configuring the `requirements.psd1` file for custom modules in Azure Functions involves specifying the PowerShell modules required by your Azure Function. Here's how you can do it:

1. Understanding the requirements.psd1 File: This file is used to list the PowerShell modules needed by your Azure Function. It is typically located in the App Files section of your Azure Function App.

2. Editing the requirements.psd1 File: You can edit this file directly in the Azure portal or through the Kudu console. The file should contain a hash table with module names as keys and version numbers as values. For example:

powershell
   @{
       'YourCustomModule' = '1.0.0'
       'AnotherModule' = '2.*'
   }
   

This specifies that your Azure Function requires `YourCustomModule` version `1.0.0` and `AnotherModule` version `2.*`.

3. Specifying Module Versions: You can specify a specific version or a version range (e.g., `2.*`) for each module. Using a version range allows for updates to be automatically downloaded if they are available.

4. Adding Custom Modules: If you have custom modules that are not available in the PowerShell Gallery, you will need to manually upload them to your Azure Function. This involves downloading the module locally, zipping it, and then uploading it to the `Modules` directory in your Azure Function's file system using the Kudu console[10].

5. Best Practices: Ensure that the modules you specify are compatible with your Azure Function's runtime environment. Also, consider pre-installing large modules to avoid timeouts during function execution[10].

By following these steps, you can effectively configure your `requirements.psd1` file to include custom modules for use in Azure Functions.

Citations:
[1] https://superuser.com/questions/1581196/how-can-i-run-psd1-and-psm1-files-in-powershell
[2] https://learn.microsoft.com/en-us/powershell/scripting/developer/module/how-to-write-a-powershell-module-manifest?view=powershell-7.5
[3] https://stackoverflow.com/questions/70604301/bicep-how-to-initialize-app-files-of-powershell-azure-function-e-g-requireme
[4] https://4bes.nl/2021/07/11/add-custom-modules-to-azure-functions-for-powershell/
[5] https://ssg.dev/powershell-accidentally-created-a-nice-configuration-format-3efde5448090
[6] https://www.youtube.com/watch?v=xPQq0ui8j78
[7] https://pnp.github.io/powershell/articles/azurefunctions.html
[8] https://stackoverflow.com/questions/77447924/azure-function-powershell-module-not-loading-from-requirements-psd1-file
[9] https://learn.microsoft.com/en-us/answers/questions/445374/function-app-app-files-requirements-psd1
[10] https://support.cloudradial.com/hc/en-us/articles/23642455028884-Installing-PowerShell-Modules-in-Azure-Functions