如何获取Invoke-AzureRmVMRunCommand命令的输出流? [英] How to get output stream for Invoke-AzureRmVMRunCommand command?
问题描述
我正在尝试运行以下命令
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屋!