{"id":158,"date":"2024-12-05T20:09:03","date_gmt":"2024-12-05T19:09:03","guid":{"rendered":"https:\/\/digitalmaterial.ch\/blog\/?p=158"},"modified":"2024-12-10T11:21:22","modified_gmt":"2024-12-10T10:21:22","slug":"azure-function-app-with-large-powershell-modules","status":"publish","type":"post","link":"https:\/\/digitalmaterial.ch\/blog\/azure-function-app-with-large-powershell-modules\/","title":{"rendered":"Azure Function App with large PowerShell Modules"},"content":{"rendered":"\n<p>Azure Function Apps can occasionally encounter challenges in downloading the required PowerShell modules within the 10-minute timeout period imposed by Microsoft during startup. To mitigate this issue, you can preload large PowerShell modules directly into the Function App&#8217;s storage, ensuring they are readily available without relying on external downloads during the initialization process. In this post, we&#8217;ll walk through all the necessary steps to ensure the required PowerShell modules are available in your Azure Function App.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Creating the Function App<\/h1>\n\n\n\n<ul start=\"1\" class=\"wp-block-list is-style-default\">\n<li>Head to the Azure Portal and create a Function App.<br><img decoding=\"async\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/msedge_cu15lOQfHu-20240924-142948-1024x569.png\" alt=\"\"><br><img decoding=\"async\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/msedge_a6exIP2i5H-20240924-142954-1024x570.png\" alt=\"\"><\/li>\n\n\n\n<li>As of 24.09.2024 be sure to use PS Core 7.4 or newer.<br><img decoding=\"async\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/msedge_FZdjA3hty9-20240924-143043-1024x567.png\" alt=\"\"><\/li>\n\n\n\n<li>Create a new storage account and add the Azure Files connection.<br><img decoding=\"async\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/msedge_cmlca1e1gu-20240924-143457-1024x573.png\" alt=\"\"><\/li>\n\n\n\n<li>Public access can be disabled, we\u2019ll enable IP based access later on:<br><img decoding=\"async\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/msedge_uY8zNLHGGG-20240924-143530-1024x570.png\" alt=\"\"><\/li>\n\n\n\n<li>To add application insights, it might need a new log analytics workspace.<br><img decoding=\"async\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/msedge_Hp99v526PB-20240924-143721-1024x572.png\" alt=\"\"><\/li>\n\n\n\n<li>Skip continuous deployment, assign relevant tags and create the function app.<br><img decoding=\"async\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/msedge_E0VbnutOhF-20240924-144101-1024x569.png\" alt=\"\"><br><\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\">Configuration of relevant settings<\/h1>\n\n\n\n<p>With our newly created Function App, we can start configuring all the relevant settings.<\/p>\n\n\n\n<ul start=\"1\" class=\"wp-block-list\">\n<li>First, it&#8217;s a good practice to restrict public access to your Function App unless explicitly required. Begin by modifying the access restrictions to limit interaction to your specific public IP address. Navigate to <strong>Settings > Networking > Public Network Access<\/strong>, and set it to <strong>Disabled<\/strong>. This will block general public access to your Function App. Later, we&#8217;ll configure IP-based access to ensure secure communication.<\/li>\n<\/ul>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/msedge_kyZiB3tGJm-20240924-150601-1024x530.png\" alt=\"\"><\/p>\n\n\n\n<ul start=\"1\" class=\"wp-block-list\">\n<li>Add the Public IP(s) from which you\u2019ll be managing the Function App.<br><img decoding=\"async\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/msedge_fpwOTrsRRI-20240924-150412-1024x570.png\" alt=\"\"><\/li>\n\n\n\n<li>Navigate to <strong>Functions<\/strong> &gt; <strong>App files<\/strong>, select <strong>host.json<\/strong>, and set the <strong>functionTimeout<\/strong> to the maximum of 10 minutes. Additionally, set <strong>managedDependency<\/strong> to <strong>false<\/strong>. Be aware that if you use managed dependencies, it may take several minutes to download the PowerShell module. Instead, we&#8217;ll upload the PowerShell module directly into the Function App storage.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">JSON<\/span><span role=\"button\" tabindex=\"0\" data-code=\"{\n    &quot;version&quot;: &quot;2.0&quot;,\n    &quot;managedDependency&quot;: {\n        &quot;Enabled&quot;: false\n    },\n    &quot;functionTimeout&quot;: &quot;00:10:00&quot;,\n    &quot;extensionBundle&quot;: {\n        &quot;id&quot;: &quot;Microsoft.Azure.Functions.ExtensionBundle&quot;,\n        &quot;version&quot;: &quot;[4.*, 5.0.0)&quot;\n    }\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">&quot;version&quot;<\/span><span style=\"color: #D4D4D4\">: <\/span><span style=\"color: #CE9178\">&quot;2.0&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">&quot;managedDependency&quot;<\/span><span style=\"color: #D4D4D4\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #9CDCFE\">&quot;Enabled&quot;<\/span><span style=\"color: #D4D4D4\">: <\/span><span style=\"color: #569CD6\">false<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">&quot;functionTimeout&quot;<\/span><span style=\"color: #D4D4D4\">: <\/span><span style=\"color: #CE9178\">&quot;00:10:00&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">&quot;extensionBundle&quot;<\/span><span style=\"color: #D4D4D4\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #9CDCFE\">&quot;id&quot;<\/span><span style=\"color: #D4D4D4\">: <\/span><span style=\"color: #CE9178\">&quot;Microsoft.Azure.Functions.ExtensionBundle&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #9CDCFE\">&quot;version&quot;<\/span><span style=\"color: #D4D4D4\">: <\/span><span style=\"color: #CE9178\">&quot;[4.*, 5.0.0)&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul start=\"1\" class=\"wp-block-list\">\n<li>Save the configuration and navigate to the next file called <strong>profile.ps1<\/strong>, where you can comment out the interaction with the Az PowerShell Module. Add lines 12 to 14 which this will append the custom PowerShell module path to <strong>$env:PSModulePath<\/strong>. Otherwise, your manually uploaded modules wouldn&#8217;t be detected. The <strong>profile.ps1<\/strong> file is loaded each time you restart the Function App. The profile script also allows you to connect to Microsoft services at startup, instead of reconnecting every time the Function App script runs.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">PowerShell<\/span><span role=\"button\" tabindex=\"0\" data-code=\"if (-not $env:PSModulePath.Split(';') -contains &quot;$env:HOME\\site\\wwwroot\\Modules&quot;) {\n    $env:PSModulePath += &quot;;$env:HOME\\site\\wwwroot\\Modules&quot;\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> (-not <\/span><span style=\"color: #9CDCFE\">$env:PSModulePath<\/span><span style=\"color: #DCDCAA\">.Split<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&#39;;&#39;<\/span><span style=\"color: #D4D4D4\">) -contains <\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #9CDCFE\">$env:HOME<\/span><span style=\"color: #CE9178\">\\site\\wwwroot\\Modules&quot;<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">$env:PSModulePath<\/span><span style=\"color: #D4D4D4\"> += <\/span><span style=\"color: #CE9178\">&quot;;<\/span><span style=\"color: #9CDCFE\">$env:HOME<\/span><span style=\"color: #CE9178\">\\site\\wwwroot\\Modules&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul start=\"1\" class=\"wp-block-list\">\n<li>Finally, the file <strong>requirements.psd1<\/strong> will not be used as long as <strong>host.json<\/strong> has <strong>managedDependency<\/strong> set to <strong>false<\/strong>. In our case, we don&#8217;t need to make any changes to this file.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">PowerShell<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# This file enables modules to be automatically managed by the Functions service.\n# See https:\/\/aka.ms\/functionsmanageddependency for additional information.\n#\n@{\n    # For latest supported version, go to 'https:\/\/www.powershellgallery.com\/packages\/Az'. \n    # To use the Az module in your function app, please uncomment the line below.\n    # 'Az' = '12.*'\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\"># This file enables modules to be automatically managed by the Functions service.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># See https:\/\/aka.ms\/functionsmanageddependency for additional information.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">@<\/span><span style=\"color: #D4D4D4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #6A9955\"># For latest supported version, go to &#39;https:\/\/www.powershellgallery.com\/packages\/Az&#39;. <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #6A9955\"># To use the Az module in your function app, please uncomment the line below.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #6A9955\"># &#39;Az&#39; = &#39;12.*&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul start=\"1\" class=\"wp-block-list\">\n<li>Under <strong>Settings, Configuration<\/strong> change the Platform to <strong>64 Bit<\/strong>.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"534\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/image-20240924-150244-1024x534.png\" alt=\"\" class=\"wp-image-172\" srcset=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/image-20240924-150244-1024x534.png 1024w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/image-20240924-150244-300x157.png 300w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/image-20240924-150244-768x401.png 768w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/image-20240924-150244.png 1347w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Uploading PowerShell Modules<\/h1>\n\n\n\n<p>Usually, the Function App is either very slow or fails to download the required PowerShell modules on its own. There&#8217;s an easy way around this if you want to directly upload the module.<\/p>\n\n\n\n<ul start=\"1\" class=\"wp-block-list\">\n<li>Head over to the connected <strong>storage account <\/strong>and generate a SAS key.<br><img decoding=\"async\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/image-20240924-152527-1024x513.png\" alt=\"\"><\/li>\n\n\n\n<li>Download the <strong>Microsoft Azure Storage Explorer<\/strong> and add the connection but be sure to add the azure file shares name to the SAS string. The string should look like the following one.<br><code><em>https:\/\/YOURSTORAGEACCOUNTNAME.file.core.windows.net\/YOURAZUREFILESHARE?sv=2022-11-02......<\/em><\/code><br><img decoding=\"async\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/StorageExplorer_rbJ87DTEZZ-20240924-132826-1024x656.png\" alt=\"\"><\/li>\n\n\n\n<li>Once added, change the directory to <strong>site\/wwwroot\/ <\/strong>and create a new folder called <strong>Modules<\/strong>.<br><img decoding=\"async\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/StorageExplorer_zza7XI6hC0-20240924-153117-1024x700.png\" alt=\"\"><\/li>\n\n\n\n<li>Copy all your needed PowerShell Module folders directly into the newly created folder <strong>Modules<\/strong>.<br><img decoding=\"async\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/explorer_r2tzmfUe8c-20240924-132934-1024x472.png\" alt=\"\"><\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\">Create a function to run a script<\/h1>\n\n\n\n<p>All required settings are set and the modules should be available to use. Open the Function App blade and add a new function.<\/p>\n\n\n\n<ul start=\"1\" class=\"wp-block-list\">\n<li>We\u2019ll use a <strong>Time trigger<\/strong> to run our script regularly.<br><img decoding=\"async\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/image-20241003-085213-1024x540.png\" alt=\"\"><br>By using the cron expression <strong>0 0 * * * *<\/strong> the function will run once an hour at minute 0.<br><img decoding=\"async\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/image-20241003-085416-1024x539.png\" alt=\"\"><\/li>\n\n\n\n<li>Click on the function you just created and open the <code>run.ps1<\/code> script for editing. When using a Timer trigger, ensure the script includes the <code>param($Timer)<\/code> declaration, as it is required for the function to execute properly. To test the functionality of your function, add the following code snippet to the <code>run.ps1<\/code> file and save the script:<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">PowerShell<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# Input bindings are passed in via param block.\nparam($Timer)\n\n# List all module paths\nWrite-Output &quot;Current PSModulePaths: $($env:PSModulePath)&quot;\n\n# List the PowerShell modules in the custom path\nGet-Module -ListAvailable -Name * | ForEach-Object {\n    Write-Host &quot;Module: $($_.Name), Path: $($_.ModuleBase)&quot;\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\"># Input bindings are passed in via param block.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">param<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$Timer<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># List all module paths<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">Write-Output<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;Current PSModulePaths: <\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #9CDCFE\">$env:PSModulePath<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># List the PowerShell modules in the custom path<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">Get-Module<\/span><span style=\"color: #D4D4D4\"> -ListAvailable -Name * | <\/span><span style=\"color: #DCDCAA\">ForEach-Object<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">Write-Host<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;Module: <\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #9CDCFE\">$_<\/span><span style=\"color: #DCDCAA\">.Name<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">, Path: <\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #9CDCFE\">$_<\/span><span style=\"color: #DCDCAA\">.ModuleBase<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This script should output the details of the previously uploaded PowerShell modules. To verify the output, check the verbose logs in Application Insights. This will confirm that the uploaded modules are correctly recognized by your Function App.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"389\" src=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/image-2-1024x389.png\" alt=\"\" class=\"wp-image-183\" srcset=\"https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/image-2-1024x389.png 1024w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/image-2-300x114.png 300w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/image-2-768x292.png 768w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/image-2-1536x583.png 1536w, https:\/\/digitalmaterial.ch\/blog\/wp-content\/uploads\/2024\/12\/image-2-2048x777.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">What Now?<\/h1>\n\n\n\n<p>If you&#8217;re interested in taking your Azure Function Apps further, check out our other blog post <a href=\"https:\/\/digitalmaterial.ch\/blog\/microsoft-graph-managed-identities\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Microsoft Graph Managed Identities \u2013 Digitalmaterial Blog<\/strong><\/a> on using <strong>managed identities<\/strong> to securely sign in to Microsoft Graph. This approach simplifies authentication while enhancing security, allowing your Function Apps to interact with Microsoft Graph without storing credentials.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Azure Function Apps can occasionally encounter challenges in downloading the required PowerShell modules within the 10-minute timeout period imposed by Microsoft during startup. To mitigate this issue, you can preload large PowerShell modules directly into the Function App&#8217;s storage, ensuring they are readily available without relying on external downloads during the initialization process. In this [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":197,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-158","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure"],"_links":{"self":[{"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/comments?post=158"}],"version-history":[{"count":8,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/posts\/158\/revisions"}],"predecessor-version":[{"id":251,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/posts\/158\/revisions\/251"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/media\/197"}],"wp:attachment":[{"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/media?parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/categories?post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/tags?post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}