Get-AzStackHCIVMVirtualMachine: Fails when $machine.Kind -eq $null

Open Beginner friendly
#27,897 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
azure, powershell
Domain
cli, cloud

Research direction

Start at custom/Get-AzStackHCIVMVirtualMachine.ps1 around line 150, where the error occurs, and inspect how Get-AzStackHCIVMMachine results are filtered by Kind. Reproduce the reported command with machines whose Kind is null, then verify the command completes and handles only the HCI guest records as intended.

Written by the indexing model from the issue text.

Description

bug customer-reported Service Attention StackHCI
Description
get-azstackhcivmvirtualmachine -SubscriptionId (get-azcontext).subscription.id
Get-AzStackHCIVMVirtualMachine: You cannot call a method on a null-valued expression.

The module internal commandlet Get-AzStackHCIVMMachine returns other machines which are Azure Arc managed, separate from HCI cluster guests. These extra objects don't have the Kind property set.

import-module az.stackhcivm
import-module ".\Documents\PowerShell\Modules\Az.StackHCIVM\1.0.3\StackHCIVM.Autorest\internal\Az.StackHCIVM.internal.psm1"
Get-AzStackHCIVMMachine | Select Location, VMId, Kind

Location      VMId                                 Kind
--------      ----                                 ----
australiaeast bb37db0f-9e62-4d0c-9a39-e05710f47566
australiaeast e839ae8a-2f1c-475c-b496-351c8bb1d8e8
australiaeast dcb41437-d625-41c4-b388-001cd8f0afdf
australiaeast 2647e3b3-0654-4e58-a1ac-3b29f5a686e5
australiaeast 08af286c-64a1-408d-b808-411bd76f6e1b
australiaeast 8290ff5a-59d7-4eb2-94a9-ab9d0e07530c
australiaeast 59a7ab76-70ce-409f-89ba-0b1a869e824e
australiaeast 4078d84c-bf31-49fa-97d1-112a58c2c545
australiaeast 3c80e9fe-761a-4dcb-a3d3-c35d171a8a9f
australiaeast 04218a46-12d6-4423-9015-1230c965a0ae
australiaeast 2c64d977-8c85-46ab-80f9-646411932472
australiaeast d639d3d5-9dfa-462a-ae86-2ba457f4531e
australiaeast 2889ee45-1184-4ae0-bb85-b3da9cbdb36c
australiaeast c0ee7f57-23a0-400c-b8da-dcdae17f317a
australiaeast c97f97b8-5c2d-48cc-bb15-e695b1f1e795 HCI
australiaeast 3e54942e-1b27-4d72-82fc-e6b268d5823d HCI
australiaeast c2cbaa82-545c-4abb-869c-050c5d49dcca HCI
Issue script & Debug output
-
Environment data
Name                           Value
----                           -----
PSVersion                      7.5.1
PSEdition                      Core
GitCommitId                    7.5.1
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Module versions
ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     5.0.2                 Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzConte…
Script     1.0.3                 az.stackhcivm                       {Add-AzStackHCIVMVirtualMachineDataDisk, Add-AzSt…
Error output
HistoryId: 3

Message        : You cannot call a method on a null-valued expression.
StackTrace     :    at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext
                 funcContext, Exception exception)
                    at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
                    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame
                 frame)
                    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame
                 frame)
                    at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
                    at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
                    at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar,
                 Object inputToProcess)
                    at System.Management.Automation.PSScriptCmdlet.DoProcessRecord()
                    at System.Management.Automation.CommandProcessor.ProcessRecord()
Exception      : System.Management.Automation.RuntimeException
InvocationInfo : {}
Line           :                 if ($machine.Kind.ToString() -eq "HCI"){

Position       : At \Documents\PowerShell\Modules
                 \az.stackhcivm\1.0.3\StackHCIVM.Autorest\custom\Get-AzStackHCIVMVirtualMachine.ps1:150 char:21
                 +                 if ($machine.Kind.ToString() -eq "HCI"){
                 +                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 3
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
3d 21h
Merged PRs (30d)
49

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Azure/azure-powershell

All issues in Azure/azure-powershell

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.