【问题标题】:To Call a File from Azure VM which resides within it using PowerShell使用 PowerShell 从驻留在其中的 Azure VM 调用文件
【发布时间】:2020-12-02 18:05:18
【问题描述】:

如何使用 Powershell(本地 ISE)调用文件路径位于 Azure VM 中的文件。

在本地计算机上使用 Powershell ISE 并尝试调用放置在 Azure Vm 中的 Ps 文件。

【问题讨论】:

  • 这取决于“调用”文件所暗示的内容 - 它是您要运行的可执行文件吗?在 VM 上还是在您的客户端上?
  • 请将其视为驻留在 Azure VM 中的 .ps1 文件

标签: azure powershell azure-powershell azure-vm


【解决方案1】:

如果您要在 VM 中运行 .ps1 文件,则可以使用 PowerShell 命令Invoke-AzVMRunCommand。您可以在本地机器上创建一个脚本,然后将您将执行的用于在 VM 中运行 .ps1 的命令放到该脚本中。例如:

本地机器中的脚本script.ps1

powershell.exe -f 'C:\script_inside_VM.ps1'    # this is the command that will run inside the VM

使用 PowerShell 命令:

Invoke-AzVMRunCommand -ResourceGroupName groupName -VMName vmName -CommandId 'RunPowerShellScript' -ScriptPath '\path\script.ps1'

【讨论】:

  • 脚本在 Azure VM 中,并希望从我的本地计算机 PS ISE 调用该文件
  • @VengateshKaliraj 我当然知道。本地脚本包含您需要在 VM 内运行以执行存储在 VM 内的脚本的命令。你明白吗?
  • 对不起,我可能用不同的方式。脚本/文件包含 Azure Vm 中的命令,我想使用 PS 从本地计算机运行/调用该文件
  • @VengateshKaliraj 你这么说是什么意思?这个答案你有什么不明白的地方?
  • 简单来说,我想从本地计算机 PS 调用 Azure VM 中的文件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-07
  • 1970-01-01
  • 2023-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多