【问题标题】:Using the 'az vm run-command' with a .ps1 file将“az vm run-command”与 .ps1 文件一起使用
【发布时间】:2018-07-25 00:35:12
【问题描述】:

我对@9​​87654325@ 有疑问。

我已经让它内联工作如下:

$resource_name="winsecagentdev2"
$resource_group="russellmccloydev"

和:

az vm run-command invoke `
-g "${resource_group}" `
-n "${resource_name}" `
--command-id 'RunPowerShellScript' `
--scripts "Write-Output 'testing russ'"

有效。

但是当我尝试使用 .ps1 文件时:

az vm run-command invoke `
-g "${resource_group}" `
-n "${resource_name}" `
--command-id 'RunPowerShellScript' `
--scripts @{'hello.ps1'} `
--parameters @{ "test" = "russell" }

我遇到了这个问题:

文档是这样说的:

所以我有点卡住了。

【问题讨论】:

    标签: powershell azure virtual-machine azure-cli2 runcommand


    【解决方案1】:

    您可以尝试将文件放入以下格式: --scripts "@hello.ps1"`

    【讨论】:

    • 你说的“放文件”是什么意思
    【解决方案2】:

    您需要将文件放入您的虚拟机并使用以下格式:

    --scripts "C:\test\hello.ps1"
    

    结果:

    【讨论】:

    • 好的,但是当我将我的脚本放在 c:\getAccessToVM.ps1 的目标机器上时,如果说找不到文件。它实际上是在调用者机器上查找文件而不是目标。
    • @RuSs 它在我这边工作得很好,你能提供错误信息吗?或者尝试我提到的路径? ps:我的虚拟机是windows操作系统。
    • 可以,但你能分享你的 hello.ps1 脚本吗?也许从那开始就不好了,然后倒退。我的也是windows虚拟机
    • @RuSs 只要在我的脚本中使用Write-Host hello,您就可以在输出中看到"message":"hello"
    • 好的.. 你是从笔记本电脑等远程机器调用 az vm run-command invoke 吗?
    【解决方案3】:

    要将脚本从远程计算机运行到 Azure 中的 Linux VM,请使用:

    az vm run-command invoke myResourceGroup -n myVm --command-id RunShellScript --scripts "@quality-check.pl" 
    

    我已将quality-check.pl 脚本复制到远程计算机上的当前位置。

    【讨论】:

    • 您上传 quality-check.pl n 服务器了吗?
    猜你喜欢
    • 1970-01-01
    • 2018-12-28
    • 2021-03-08
    • 1970-01-01
    • 1970-01-01
    • 2021-05-13
    • 1970-01-01
    • 1970-01-01
    • 2020-12-01
    相关资源
    最近更新 更多