Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How do I ensure my Function App has access to the PowerShell gallery


How do I ensure my Function App has access to the PowerShell gallery


Ensuring your Azure Function App has access to the PowerShell Gallery involves several steps, especially when dealing with large or frequently updated modules. Here's how you can manage this:

1. Enable Managed Dependencies: By default, Azure Functions can automatically download and manage PowerShell modules specified in the `requirements.psd1` file. This is convenient but may cause issues if the PowerShell Gallery is unreachable or if modules are too large to download within the timeout period[3][5].

2. Specify Modules in `requirements.psd1`: If you choose to use managed dependencies, list the required modules in the `requirements.psd1` file. For example, to use the Az module, uncomment the line `'Az' = '13.*'` in the file[9].

3. Preload Large Modules: For large modules or when using the Consumption plan, it's better to preload them into your Function App's storage. This involves downloading the module locally, compressing it, and uploading it to the `wwwroot\Modules` directory in your Function App[1][3].

4. Configure `host.json`: Ensure that `managedDependency` is set to `false` in `host.json` if you manually upload modules. This prevents the Function App from attempting to download modules automatically[1].

5. Update `profile.ps1`: Modify the `profile.ps1` file to include the custom module path in `$env:PSModulePath`. This ensures that your manually uploaded modules are detected by PowerShell[1].

6. Check Network Access: Ensure your Function App has access to the PowerShell Gallery by checking its network settings. If you restrict public access, make sure the IP address of your Function App can reach the gallery[1].

By following these steps, you can ensure your Azure Function App has reliable access to the PowerShell Gallery and can manage large or critical modules effectively.

Citations:
[1] https://digitalmaterial.ch/blog/azure-function-app-with-large-powershell-modules/
[2] https://practical365.com/how-to-use-internal-powershell-gallery-app/
[3] https://support.cloudradial.com/hc/en-us/articles/23642455028884-Installing-PowerShell-Modules-in-Azure-Functions
[4] https://learn.microsoft.com/en-us/azure/azure-functions/functions-app-settings
[5] https://about-powershell.com/blog/azure-functions-fails-when-powershell-gallery-is-not-reachable-powershell-worker-runtime/
[6] https://pnp.github.io/powershell/articles/azurefunctions.html
[7] https://techcommunity.microsoft.com/blog/appsonazureblog/steps-to-manually-add-powershell-modules-in-function-app/4163463
[8] https://laurakokkarinen.com/how-to-use-pnp-powershell-on-azure-functions-with-application-permissions/
[9] https://dev.to/rokicool/azure-function-app-flex-consumption-powershell-modules-solution-1hfg