Hi @Ryan Wong ,
if you use Invoke-AzVMRunCommand
it will be recorded in the Activity Log
of the VM.
There should be 3 events in the 'Activity Log' per RunCommand with Status Accepted
, Started
and Succeeded
(or Failed
if Invoke-AzVMRunCommand
is not able to execute the RunCommand).
You can get the ActivityLog details for the VM with this PowerShell script:
$vm = "TestVM01"
$activityLog = Get-AzLog -ResourceId "$($(Get-AzVM -Name "$vm").Id)" -MaxRecord 50
$activityLog | Where-Object { $_.OperationName -eq "Run Command on Virtual Machine" } |
Sort-Object -Property SubmissionTimestamp, CorrelationId -Descending |
Select-Object OperationName, EventName, CorrelationId, SubmissionTimestamp, Status |
Format-Table -AutoSize
The result should look like this:
Run Command on Virtual Machine End request 3bdf8654-38e8-449a-9a2a-2d5e4f6dcbba 30.08.2022 08:03:20 Succeeded
Run Command on Virtual Machine Begin request 3bdf8654-38e8-449a-9a2a-2d5e4f6dcbba 30.08.2022 08:02:28 Started
Run Command on Virtual Machine End request 3bdf8654-38e8-449a-9a2a-2d5e4f6dcbba 30.08.2022 08:02:28 Accepted
If the Succeeded
line is missing but you get a Accepted
and Started
line the RunCommand should be still in progress. The CorrelationId
is the reference ID of each RunCommand.
----------
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Andreas Baumgarten