【问题标题】:Unable to run remote powershell script which is located in remote Azure VM D: drive using Invoke-Command无法运行位于远程 Azure VM D 中的远程 powershell 脚本:使用 Invoke-Command 的驱动器
【发布时间】:2020-04-05 10:11:39
【问题描述】:

我尝试在本地机器上使用以下脚本运行位于remote azure vm 中的remote powershell script

我可以通过powershell pssession 连接到azure remote vm,但Invoke-Command 没有返回任何内容。无法运行remote powershell script

我也试过了

但是 -FilePath 试图查看本地机器 D: 驱动器而不是远程 azure vm D: 驱动器。

如何运行位于远程 azure vm D: 驱动器中的远程 azure vm powershell 脚本

【问题讨论】:

  • 请不要将代码添加为图像。相反,编辑问题并将代码添加为格式化文本。

标签: powershell azure-virtual-machine


【解决方案1】:

我的猜测是问题可能出在您的GetRemoteAzureVMHstName.ps1 脚本上。

确保它确实在打印一些东西。

【讨论】:

【解决方案2】:

我的脚本现在运行良好。

Invoke-Command 中,对于-Command,我删除了脚本文件路径的单引号并且它起作用了。

Invoke-Command 应该如下

Invoke-Command -Session $s -Command { D:\User1\GetRemoteAzureVMHstName.ps1 }

而不是下面

Invoke-Command -Session $s -Command { 'D:\User1\GetRemoteAzureVMHstName.ps1' }

【讨论】:

    猜你喜欢
    • 2014-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-21
    • 2016-12-05
    • 1970-01-01
    • 2018-12-02
    • 1970-01-01
    相关资源
    最近更新 更多