Repository: PowerShell/PowerShell
File: src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs (C#)

Code before:
            /// <summary>
            /// FastSavedCritical. Critical states.
            /// </summary>
            FastSavedCritical,

            /// <summary>
            /// FastSavingCritical. Critical states.
            /// </summary>
            FastSavingCritical,
        }

#nullable enable
        /// <summary>
        /// Get the State property from Get-VM result.
        /// </summary>
        /// <param name="value">The raw PSObject as returned by Get-VM.</param>
        /// <returns>The VMState value of the State property if present and parsable, otherwise null.</returns>
        internal VMState? GetVMStateProperty(PSObject value)
        {
            ReadOnlyPSMemberInfoCollection<PSPropertyInfo> stateProps = value.Properties.Match("State");
            if (stateProps.Count == 0)
            {
                return null;
            }

            object? rawState = stateProps[0].Value;
            if (rawState is Enum enumState)
            {
                // If the Hyper-V module was directly importable we have the VMState enum
                // value which we can just cast to our VMState type.
                return (VMState)enumState;
            }
            else if (rawState is string stringState && Enum.TryParse(stringState, true, out VMState result))
            {
                // If the Hyper-V module was imported through implicit remoting on old
                // Windows versions we get a string back which we will try and parse
                // as the enum label.
                return result;
            }

            // Unknown scenario, this should not happen.
            return null;
        }
#nullable disable

        #endregion

        #region Tracer

        // PSETWTracer tracer = PSETWTracer.GetETWTracer(PSKeyword.Runspace);


Review comment (suggestion):
Will this work?
```suggestion
            if (rawState is VMState result)
            {
                // If the Hyper-V module was directly importable we have the VMState enum
                // value which we can just cast to our VMState type.
                return result;
            }
```

Code after:
            /// <summary>
            /// FastSavedCritical. Critical states.
            /// </summary>
            FastSavedCritical,

            /// <summary>
            /// FastSavingCritical. Critical states.
            /// </summary>
            FastSavingCritical,
        }

#nullable enable
        /// <summary>
        /// Get the State property from Get-VM result.
        /// </summary>
        /// <param name="value">The raw PSObject as returned by Get-VM.</param>
        /// <returns>The VMState value of the State property if present and parsable, otherwise null.</returns>
        internal VMState? GetVMStateProperty(PSObject value)
        {
            object? rawState = value.Properties["State"].Value;
            if (rawState is Enum enumState)
            {
                // If the Hyper-V module was directly importable we have the VMState enum
                // value which we can just cast to our VMState type.
                return (VMState)enumState;
            }
            else if (rawState is string stringState && Enum.TryParse(stringState, true, out VMState result))
            {
                // If the Hyper-V module was imported through implicit remoting on old
                // Windows versions we get a string back which we will try and parse
                // as the enum label.
                return result;
            }

            // Unknown scenario, this should not happen.
            string message = PSRemotingErrorInvariants.FormatResourceString(
                RemotingErrorIdStrings.HyperVFailedToGetStateUnknownType,
                rawState?.GetType()?.FullName ?? "null");
            throw new InvalidOperationException(message);
        }
#nullable disable

        #endregion

        #region Tracer

        // PSETWTracer tracer = PSETWTracer.GetETWTracer(PSKeyword.Runspace);

        #endregion Tracer

        #region Properties