Skip to content

Commit b47f246

Browse files
authored
Use last PowerState instance in Statuses for power status (#15941)
* Use last PowerState instance in Statuses * Update changelog
1 parent 2511b07 commit b47f246

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/Compute/Compute/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
-->
2222
## Upcoming Release
2323
* Update Compute .NET SDK package reference to version 49.1.0
24+
* Fixed a bug in `Get-AzVM` that caused incorrect power status output.
2425

2526
## Version 4.17.0
2627
* Added new parameters `-LinuxConfigurationPatchMode`, `-WindowsConfigurationPatchMode`, and `-LinuxConfigurationProvisionVMAgent` to `Set-AzVmssOSProfile`

src/Compute/Compute/VirtualMachine/Operation/GetAzureVMCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using System;
1616
using System.Collections.Generic;
17+
using System.Linq;
1718
using System.Management.Automation;
1819
using System.Threading;
1920
using System.Threading.Tasks;
@@ -226,7 +227,8 @@ private List<PSVirtualMachineListStatus> GetPowerstate(
226227
var psstate = state.ToPSVirtualMachineInstanceView(psItem.ResourceGroupName, psItem.Name);
227228
if (psstate != null && psstate.Statuses != null && psstate.Statuses.Count > 1)
228229
{
229-
psItem.PowerState = psstate.Statuses[1].DisplayStatus;
230+
var powerStatus = psstate.Statuses.LastOrDefault(s => s.Code.StartsWith("PowerState"));
231+
psItem.PowerState = powerStatus != null ? powerStatus.DisplayStatus : InfoNotAvailable;
230232
}
231233
else
232234
{

0 commit comments

Comments
 (0)