Skip to content

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

Open
@davepushbutton

Description

@davepushbutton

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Service AttentionThis issue is responsible by Azure service team.StackHCIbugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reported

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions