【问题标题】:include and import azure rm module for powershell script in azure function在 azure 函数中包含和导入用于 powershell 脚本的 azure rm 模块
【发布时间】:2019-09-12 17:52:30
【问题描述】:

我正在尝试使用 azure 函数建立 powershell 脚本的计划运行。 我的问题是 powershell 脚本包含 azureRM cmdlts,当我尝试运行脚本时,它给了我一个错误: “未加载指定的模块‘AzureRM’,因为在任何模块目录中都找不到有效的模块文件。”

根据文档,azure 模块是原生可用的,只需要确保这两个文件包含以下内容:

**host.json**
{
    “version”: “2.0”,
    “managedDependency”: {
       “Enabled”: “true”
    }
}

**Requirements.psd1**
@{
    Az = ‘1.*’
}

为了解决这个问题,我使用了 Kudu 工具并确保我在上述文件中有这些值。在脚本中我添加了一行

Import-Module -Name AzureRM

不幸的是,到目前为止没有成功 - 仍然是同样的错误。 有谁知道如何导入这个模块并使脚本在 azure 函数中工作? 将不胜感激。

【问题讨论】:

    标签: azure powershell azure-functions azure-rm


    【解决方案1】:

    Azure Functions v2.0 不支持 AzureRM 模块,请改用 Az

    如果从 profile.ps1 调用 Enable-AzureRmAlias,则可以使用 Az 提供的 AzureRM cmdlet 别名。当您创建一个新的 PowerShell 应用程序时,您自动生成的 profile.ps1 通常会包含以下内容:

    # Authenticate with Azure PowerShell using MSI.
    # Remove this if you are not planning on using MSI or Azure PowerShell.
    if ($env:MSI_SECRET -and (Get-Module -ListAvailable Az.Accounts)) {
        Connect-AzAccount -Identity
    }
    
    # Uncomment the next line to enable legacy AzureRm alias in Azure PowerShell.
    # Enable-AzureRmAlias
    

    另外,请考虑在您的 requirements.psd1 中将 Az = ‘1.*’ 替换为 Az = ‘2.*’

    【讨论】:

    • 你现在可以选择'3.*'!很快就会是 4.*
    猜你喜欢
    • 2019-11-14
    • 1970-01-01
    • 2021-02-18
    • 1970-01-01
    • 2016-11-13
    • 2019-12-15
    • 1970-01-01
    • 1970-01-01
    • 2016-11-07
    相关资源
    最近更新 更多