在 azure 函数中包含并导入用于 powershell 脚本的 azure rm 模块
include and import azure rm module for powershell script in azure function
我正在尝试使用 azure 函数建立预定的 运行 powershell 脚本。
我的问题是 powershell 脚本包含 azureRM cmdlts,当我尝试 运行 脚本时,它给我一个错误:
"The specified module 'AzureRM' was not loaded because no valid module file was found in any module directory."
根据文档 azure 模块是本地可用的,只需要确保这两个文件包含以下内容:
**host.json**
{
“version”: “2.0”,
“managedDependency”: {
“Enabled”: “true”
}
}
**Requirements.psd1**
@{
Az = ‘1.*’
}
为了解决这个问题,我使用了 Kudu 工具并确保我在上面的文件中有这些值。在脚本中我添加了一行
Import-Module -Name AzureRM
不幸的是,到目前为止没有成功 - 仍然是同样的错误。
有谁知道如何导入这个模块并使脚本在 azure 函数中工作?
将不胜感激。
Azure Functions v2.0 不支持 AzureRM 模块,请改用 Az。
如果您从配置文件调用 Enable-AzureRmAlias
。ps1,您可以使用 Az 提供的 AzureRM cmdlet 别名。当您创建新的 PowerShell 应用程序时,您自动生成的配置文件。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.*’
我正在尝试使用 azure 函数建立预定的 运行 powershell 脚本。 我的问题是 powershell 脚本包含 azureRM cmdlts,当我尝试 运行 脚本时,它给我一个错误: "The specified module 'AzureRM' was not loaded because no valid module file was found in any module directory."
根据文档 azure 模块是本地可用的,只需要确保这两个文件包含以下内容:
**host.json**
{
“version”: “2.0”,
“managedDependency”: {
“Enabled”: “true”
}
}
**Requirements.psd1**
@{
Az = ‘1.*’
}
为了解决这个问题,我使用了 Kudu 工具并确保我在上面的文件中有这些值。在脚本中我添加了一行
Import-Module -Name AzureRM
不幸的是,到目前为止没有成功 - 仍然是同样的错误。 有谁知道如何导入这个模块并使脚本在 azure 函数中工作? 将不胜感激。
Azure Functions v2.0 不支持 AzureRM 模块,请改用 Az。
如果您从配置文件调用 Enable-AzureRmAlias
。ps1,您可以使用 Az 提供的 AzureRM cmdlet 别名。当您创建新的 PowerShell 应用程序时,您自动生成的配置文件。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.*’