Edit

Share via


Get-AzVMRunCommand

Gets a specific Run Command or a list of Run Commands for a Virtual Machine

Syntax

Default (Default)

Get-AzVMRunCommand
    -ResourceGroupName <String>
    -VMName <String>
    [-RunCommandName <String>]
    [-Expand <String>]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

Description

Gets specific run command for a subscription in a location.

Examples

Example 1: Get a Run Command for VM.

Get-AzVMRunCommand -ResourceGroupName MyRG -VMName MyVM -RunCommandName MyRunCommand

Get a Run Command for VM without Instance View.

Example 2: Get a Run Command for VM with Instance View

$x = Get-AzVMRunCommand -ResourceGroupName MyRG -VMName MyVM -RunCommandName MyRunCommand -Expand InstanceView
$x.InstanceView
ExecutionState   : Succeeded
ExecutionMessage :
ExitCode         : 0
Output           :     Directory: C:\


                   Mode                 LastWriteTime         Length Name
                   ----                 -------------         ------ ----
                   -a----        10/27/2022   9:10 PM              0 HelloWorld2022-10-27T21.10.54.9266231+00.00.txt


Error            :
StartTime        : 10/27/2022 9:10:52 PM
EndTime          : 10/27/2022 9:10:55 PM
Statuses         :

Get a Run Command for VM with Instance View. Instance View contains execution state of run command (Succeeded, Failed, etc.), exit code, standard output and standard error generated by executing the script using Run Command. A non-zero ExitCode indicates an unsuccessful execution.

Example 3: Get all Run Commands for a VM

Get-AzVMRunCommand -ResourceGroupName MyRG -VMName MyVM

Get all Run Commands for a VM

Parameters

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with Azure.

Parameter properties

Type:IAzureContextContainer
Default value:None
Supports wildcards:False
DontShow:False
Aliases:AzContext, AzureRmContext, AzureCredential

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Expand

The expand expression to apply on the operation. Possible value(s): InstanceView

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-ResourceGroupName

Name of the resource group for the run command.

Parameter properties

Type:String
Default value:None
Supports wildcards:True
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-RunCommandName

The name of the virtual machine run command.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-VMName

The name of the virtual machine containing the run command.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

String

Outputs

PSVirtualMachineRunCommand