我想从本地和 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。得到一个错误。
您得到的错误意味着您在 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] 删除。
我来说两句