如何获取Invoke-AzureRmVMRunCommand命令的输出流? [英] How to get output stream for Invoke-AzureRmVMRunCommand command?

查看:107
本文介绍了如何获取Invoke-AzureRmVMRunCommand命令的输出流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行以下命令

  Invoke-AzVMRunCommand -ResourceGroupName $ instance.ResourceGroupName -Name $ instance.Name -CommandId'RunPowerShellScript'-ScriptPath'C:\ Users \ tushar.raichand \ Desktop \ sample.ps1' 

Sample.ps1如下

  $ output = Get-LocalUser写输出$ output$输出 

我为Invoke-AzVMRunCommand获得的输出是

  Microsoft.Azure.Commands.Compute.Automation.Models.PSRunCommandResult 

解决方案

首先,确保您具有足够的权限来显示命令的详细信息,请参见

I am trying to run the below command

Invoke-AzVMRunCommand -ResourceGroupName $instance.ResourceGroupName -Name $instance.Name -CommandId 'RunPowerShellScript' -ScriptPath 'C:\Users\tushar.raichand\Desktop\sample.ps1'

Sample.ps1 is as below

$output = Get-LocalUser
Write-Output $output
$output

The output i am getting for Invoke-AzVMRunCommand is

Microsoft.Azure.Commands.Compute.Automation.Models.PSRunCommandResult

解决方案

First, make sure you have enough permission to show the details of a command, see Limiting access to Run Command:

Listing the run commands or showing the details of a command require the Microsoft.Compute/locations/runCommands/read permission, which the built-in Reader role and higher have.

Besides, the command Invoke-AzureRmVMRunCommand belongs to the AzureRM powershell module which has been deprecated, you may need to upgrade it to the new Az module, refer to this link to upgrade.

I test the script with the new Az command Invoke-AzVMRunCommand, it works fine.

Invoke-AzVMRunCommand -ResourceGroupName joywebapp -Name joyVM -CommandId 'RunPowerShellScript' -ScriptPath 'C:\Users\joyw\Desktop\sample.ps1'

sample.ps1:

$output = Get-LocalUser
Write-Output $output

Result:

这篇关于如何获取Invoke-AzureRmVMRunCommand命令的输出流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆