none
Azure Function Runtime for Powershell language needs to support the AzureRM.ContainerRegistry module RRS feed

  • Question

  • I was creating an Azure Function that would provision an Azure Container Image via PowerShell commands. 

    But Azure Functions don't yet have the AzureRM.ContainerRegistry module available. Since Azure Functions support PowerShell 4.0, it should be able to include the ContainerRegistry module without much challenge. 

    Can you guys make that happen?


    Build cool stuff.

    Saturday, February 24, 2018 11:52 PM

Answers

  • Azure Functions is running on PowerShell 5.1 now.  PowerShell support is in experimental mode at the moment, so we do not recommend using PowerShell in Azure Functions for production scenarios.  We are actively working with the PowerShell team to provide 1st class support for PowerShell in Functions v2 but will not be able to provide an ETA at this time.

    But, if you want to run non-production workloads using PowerShell in Azure Functions and want to use your own versions of Azure PowerShell modules, you may try the steps mentioned here:

    https://github.com/Azure/Azure-Functions/issues/124#issuecomment-27784870

    • Edited by Ling Toh Sunday, February 25, 2018 4:53 AM
    • Marked as answer by IrwinWilliams Monday, February 26, 2018 9:02 AM
    Sunday, February 25, 2018 4:51 AM

All replies

  • You can actually access that module now by adding it to a folder called Modules that is located in the same directory where the PowerShell script resides. You can use the Kudu interface to add it or you can do it through the portal on the files tab to the right in our function. If the folder doesn't exist, you will need to use Kudu simply create the folder (in the debug console tab - image at end of post) and place all dependent files in the folder at the root (.psm1, .psd1, .dll, etc). Once you do that all modules in the modules directory are automatically loaded so there is no need for import-module or anything, it just works.

    As far as feedback:

    Azure Functions is totally open source so you can provide this feedback at: 

    https://github.com/Azure/Azure-Functions

    Also for anything Azure, provide feedback here:

    https://feedback.azure.com/forums/34192--general-feedback

    I hope that helps and if it does be sure to mark as answered and PowerShell on my friend!

    ~Theo





    Sunday, February 25, 2018 1:26 AM
  • Azure Functions is running on PowerShell 5.1 now.  PowerShell support is in experimental mode at the moment, so we do not recommend using PowerShell in Azure Functions for production scenarios.  We are actively working with the PowerShell team to provide 1st class support for PowerShell in Functions v2 but will not be able to provide an ETA at this time.

    But, if you want to run non-production workloads using PowerShell in Azure Functions and want to use your own versions of Azure PowerShell modules, you may try the steps mentioned here:

    https://github.com/Azure/Azure-Functions/issues/124#issuecomment-27784870

    • Edited by Ling Toh Sunday, February 25, 2018 4:53 AM
    • Marked as answer by IrwinWilliams Monday, February 26, 2018 9:02 AM
    Sunday, February 25, 2018 4:51 AM
  • @Ling

    Those instructions are only if you have mismatched modules, no import-module is required unless there is a mismatch. In this case they will be putting a lone version in the modules directory and with PowerShell 3.0+ there is no longer a need for running a import-module as the modules are automatically loaded.

    @IrwimWilliams

    Please follow the instructions I gave you, they are tested and work.

    ~Theo

    Sunday, February 25, 2018 5:50 AM
  • @IrwimVilliams - Theo is correct in that my suggestions do not apply if there are no issues with mismatched modules. You should follow his instructions since they are tested and works.

    • Edited by Ling Toh Sunday, February 25, 2018 6:17 AM
    Sunday, February 25, 2018 6:00 AM
  • Thanks, Theo.

    I tried downloading the modules (AzureRM.ContainerInstance, AzureRM.ContainerRegistry and AzureRM.Profile). 

    Both ContainerInstance and ContainerRegistry need Profile (v4.1.1+ and v4.2.0+) however, when I tried to load Profile using, both allowing the implicit call and then directly putting

    Import-Module .\Modules\AzureRM.Profile\4.2.0\AzureRM.Profile.psd1

    I get failures in the function invocation. 

    This is the log from the Azure Function call (sorry for the formatting):

    2018-02-25T17:32:51  Welcome, you are now connected to log-streaming service.2018-02-25T17:32:53.949 [Error] Import-Module : The specified module 'AzureRM.Profile' with version '4.2.0' was not loaded because no valid module file was found in any module directory.at <ScriptBlock>, /CardiViaHttp/modules/AzureRM.ContainerInstance/0.2.2/AzureRM.ContainerInstance.psm1: line 19+ Import-Module+ _____________    + CategoryInfo          : ResourceUnavailable: (AzureRM.Profile:String) [Import-Module], FileNotFoundException    + FullyQualifiedErrorId : Modules_ModuleWithVersionNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand2018-02-25T17:32:54.105 [Error] Import-Module : Could not load file or assembly 'Microsoft.Azure.Commands.ResourceManager.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.at <ScriptBlock>, /CardiViaHttp/modules/AzureRM.ContainerInstance/0.2.2/AzureRM.ContainerInstance.psm1: line 21+ Import-Module+ _____________    + CategoryInfo          : NotSpecified: (:) [Import-Module], FileNotFoundException    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand2018-02-25T17:32:55.594 [Error] Import-Module : The specified module 'AzureRM.Profile' with version '4.1.1' was not loaded because no valid module file was found in any module directory.at <ScriptBlock>, /CardiViaHttp/modules/AzureRM.ContainerRegistry/1.0.1/AzureRM.ContainerRegistry.psm1: line 19+ Import-Module+ _____________    + CategoryInfo          : ResourceUnavailable: (AzureRM.Profile:String) [Import-Module], FileNotFoundException    + FullyQualifiedErrorId : Modules_ModuleWithVersionNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand2018-02-25T17:32:55.687 [Error] Import-Module : Could not load file or assembly 'Microsoft.Azure.Commands.ResourceManager.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.at <ScriptBlock>, /CardiViaHttp/modules/AzureRM.ContainerRegistry/1.0.1/AzureRM.ContainerRegistry.psm1: line 21+ Import-Module+ _____________    + CategoryInfo          : NotSpecified: (:) [Import-Module], FileNotFoundException    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand2018-02-25T17:32:56.769 [Error] Import-Module : The required module 'AzureRM.Profile' is not loaded. Load the module or remove the module from 'RequiredModules' in the file 'D:\home\site\wwwroot\CardiViaHttp\modules\AzureRM.ContainerRegistry\1.0.1\AzureRM.Resources.psd1'.+ Import-Module+ _____________    + CategoryInfo          : ResourceUnavailable: (D:\home\site\ww....Resources.psd1:String) [Import-Module], MissingMemberException    + FullyQualifiedErrorId : Modules_InvalidManifest,Microsoft.PowerShell.Commands.ImportModuleCommand.2018-02-25T17:32:56.800 [Error] Import-Module : The required module 'AzureRM.Profile' is not loaded. Load the module or remove the module from 'RequiredModules' in the file 'D:\home\site\wwwroot\CardiViaHttp\modules\AzureRM.ContainerRegistry\1.0.1\AzureRM.Resources.psd1'.+ Import-Module+ _____________    + CategoryInfo          : ResourceUnavailable: (D:\home\site\ww....Resources.psd1:String) [Import-Module], MissingMemberException    + FullyQualifiedErrorId : Modules_InvalidManifest,Microsoft.PowerShell.Commands.ImportModuleCommand2018-02-25T17:32:57.456 [Error] Import-Module : The specified module 'AzureRM.Profile' with version '4.2.0' was not loaded because no valid module file was found in any module directory.at <ScriptBlock>, /CardiViaHttp/modules/AzureRM.ContainerRegistry/1.0.2/AzureRM.ContainerRegistry.psm1: line 19+ Import-Module+ _____________    + CategoryInfo          : ResourceUnavailable: (AzureRM.Profile:String) [Import-Module], FileNotFoundException    + FullyQualifiedErrorId : Modules_ModuleWithVersionNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand2018-02-25T17:32:57.503 [Error] Import-Module : Could not load file or assembly 'Microsoft.Azure.Commands.ResourceManager.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.at <ScriptBlock>, /CardiViaHttp/modules/AzureRM.ContainerRegistry/1.0.2/AzureRM.ContainerRegistry.psm1: line 21+ Import-Module+ _____________    + CategoryInfo          : NotSpecified: (:) [Import-Module], FileNotFoundException    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand2018-02-25T17:32:57.566 [Error]  : Exception calling "Add" with "2" argument(s): "The key 'New-AzureRmContainerRegistry:ResourceGroupName' has already been added to the dictionary."at <ScriptBlock>, /CardiViaHttp/modules/AzureRM.ContainerRegistry/1.0.2/AzureRM.ContainerRegistry.psm1: line 55 at <ScriptBlock>, /CardiViaHttp/modules/AzureRM.ContainerRegistry/1.0.2/AzureRM.ContainerRegistry.psm1: line 54+ +     + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException    + FullyQualifiedErrorId : PSArgumentException,run.ps12018-02-25T17:32:58.206 [Error] Import-Module : The required module 'AzureRM.Profile' is not loaded. Load the module or remove the module from 'RequiredModules' in the file 'D:\home\site\wwwroot\CardiViaHttp\modules\AzureRM.ContainerRegistry\1.0.2\AzureRM.Resources.psd1'.+ Import-Module+ _____________    + CategoryInfo          : ResourceUnavailable: (D:\home\site\ww....Resources.psd1:String) [Import-Module], MissingMemberException    + FullyQualifiedErrorId : Modules_InvalidManifest,Microsoft.PowerShell.Commands.ImportModuleCommand.2018-02-25T17:32:58.269 [Error] Import-Module : The required module 'AzureRM.Profile' is not loaded. Load the module or remove the module from 'RequiredModules' in the file 'D:\home\site\wwwroot\CardiViaHttp\modules\AzureRM.ContainerRegistry\1.0.2\AzureRM.Resources.psd1'.+ Import-Module+ _____________    + CategoryInfo          : ResourceUnavailable: (D:\home\site\ww....Resources.psd1:String) [Import-Module], MissingMemberException    + FullyQualifiedErrorId : Modules_InvalidManifest,Microsoft.PowerShell.Commands.ImportModuleCommand


    Build cool stuff.

    Sunday, February 25, 2018 5:38 PM
  • @IrwinWilliams

    I created a blog for you to follow, your issue is you are putting them in sub folders/containers and the Azure Functions Host process cannot handle loading them that way. Here is the blog post:

    Add a custom or non-standard PowerShell module to Azure Functions

    https://blogs.technet.microsoft.com/thbrown/2018/02/25/add-a-custom-or-non-standard-powershell-module-to-azure-functions/

    Hope that helps and if it does be sure to mark as answered!

    PowerShell and Azure on my friend!

    ~Theo

    Sunday, February 25, 2018 9:29 PM
  • Thanks much, Theo.

    As you can see here, I did put the modules directory at the same level as the .json and run.ps1 files.

    

    I think my issue is that the installed AzureRM.Profile module and the one I need for AzureRM.ContainerInstance (v4.1.1) along with for AzureRM.ContainerRegistry(v4.2.0) are conflicting. 

    This is the log entry that comes up when I run the Import-Module AzureRM.ContainerRegistry

    PS D:\home\site\wwwroot\CardiViaHttp> Import-Module AzureRM.ContainerRegistry Import-Module AzureRM.ContainerRegistry

    D:\home\site\wwwroot\CardiViaHttp\Modules\AzureRM.ContainerRegistry\1.0.2\Azure RM.ContainerRegistry.psm1 : This module requires AzureRM.Profile version 4.2.0. An earlier version of AzureRM.Profile is imported in the current PowerShell session. Please open a new session before importing this module. This error could indicate that multiple incompatible versions of the Azure PowerShell cmdlets are installed on your system.


    Build cool stuff.

    Monday, February 26, 2018 2:22 AM
  • So now you are running into the issue Ling was speaking of above, read her febuary 16th post here: https://github.com/Azure/Azure-Functions/issues/124#issuecomment-27784870

    ~Theo

    Monday, February 26, 2018 2:32 AM
  • Great, thanks Ling! Thanks, Theo! 

    It works. I had to import all three modules using that strategy. On with our story! :) 


    Build cool stuff.

    Monday, February 26, 2018 5:00 AM
  • Fantastic and glad we could help, please mark as answered and Azure on!

    ~Theo

    Monday, February 26, 2018 5:52 AM