我正在尝试使用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函数中工作? 将不胜感激。
答案 0 :(得分: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.*’
。