如何从本地和 azure 从 terraform 在 azure 中执行 PowerShell 文件

AKR

我想从本地和 azure 从 terraform 执行存储在 Azure 存储帐户上的 PowerShell 文件。

我在我的 terraform 脚本中包含了配置器来执行 PowerShell 文件

resource "azurerm_automation_account" "my_acc" {

  name                = "AUT-ACCOUNT-586"
  location            = "${azurerm_resource_group.rg_obj.location}"
  resource_group_name = "${azurerm_resource_group.rg_obj.name}"
  sku_name  = "Basic"  

   provisioner "local-exec" {
    command = "http://${azurerm_storage_account.storageaccount.name}.blob.core.windows.net/${azurerm_storage_container.blobstorage.name}/Import-PowerShell-Modules.ps1"
    interpreter = ["PowerShell","-Command"]
  }
}

我希望 PowerShell 文件得到执行。

输出是术语“ http://MyStorage.blob.core.windows.net/scripts/Import-PowerShell-Modules.ps1 ”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。在 line:1 char:1 + http://MyStorage.blob.core.windows.net/scripts/Import-PowerShell ... + ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: ( http://MyStorage...ell-Modules.ps1:String ) [], CommandNotFoundException +fullyQualifiedErrorId : CommandNotFoundException。得到一个错误。

Charles Xu

您得到的错误意味着您在 local-exec 配置器中使用的命令不是 PowerShell 命令。

执行存储在本地的 PowerShell 脚本。您可以像这样使用代码:

provisioner "local-exec" {
        command = "powershell -file ./test.ps1"
    }

您可以使用文件的相对路径或绝对路径。命令powershell -file显示在这里:

-File
    Runs the specified script in the local scope ("dot-sourced"), so that the
    functions and variables that the script creates are available in the
    current session. Enter the script file path and any parameters.
    File must be the last parameter in the command, because all characters
    typed after the File parameter name are interpreted
    as the script file path followed by the script parameters.

所以我建议如果你想执行存储在Azure存储帐户中的PowerShell脚本,你最好下载脚本或在本地创建一个脚本来下载脚本的内容并执行它。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用Azure Powershell执行.sql文件

如何更新Azure PowerShell?

如何使用PowerShell在Azure Function中加载文件

在Azure Web应用程序中对本地文件执行GET时获得“ 404未找到”

如何在Terraform文件中为Azure DevOps / VSTS引用变量

如何在Azure Functions中添加和执行二进制文件?

如何在Powershell Core Azure函数中写入文件

如何在Powershell中使用Azure Function应用写入文件

如何使用Azure DevOps Server 2019(本地)中的Azure Service Connection从发布阶段运行的脚本运行terraform?

文件上传的Terraform Azure功能应用

将输出从terraform传递到Azure后端存储中具有状态文件的Azure Devops Pipeline

CSV文件中的Azure Powershell标记VM

Azure上的Terraform:使用变量作为参数从本地文件执行Windows VM的Powershell脚本

如何在Azure Cloud Service WebRole中引用本地文件

Azure Powershell ISE执行查询

PowerShell中的Azure函数解压缩文件

无法从 terraform 在 azure VM 中执行自定义数据

如何使用powershell在azure web app中创建文件夹和添加文件

如何通过 Azure powershell 或 Azure CLI 将 html 文件从 Azure VM 传输到本地计算机

在 Azure DevOps 管道中从 PowerShell 运行 Terraform

使用 Azure CLI 命令将本地 bash 脚本迁移到 Azure DevOps 中的 Azure Powershell 任务

内联脚本中的 Azure powershell 提及文件路径

Azure DevOps terraform 和 AKV

Azure DevOps 中的 Terraform local-exec Powershell 错误:运行 Connect-AzAccount 登录

Azure 函数“本地”文件

如何匹配 Powershell Azure VM 中的对象

在 Azure 管道中,Powershell 如何使任务失败?

使用 Powershell 和 csv 文件从 Azure AD 检索用户

如何使用 Terraform 连接到 Azure 中的 terraform 状态文件