private/Test-HyperVEnabled.ps1

function Test-HyperVEnabled {
    <#
    .SYNOPSIS
        Tests whether the Hyper-V optional feature state is Enabled
 
    .DESCRIPTION
        Queries the Microsoft-Hyper-V-All optional feature in the running
        Windows installation. Returns $true only when its state is Enabled.
        Returns $false for all other states, when Get-WindowsOptionalFeature is
        unavailable, or when the query fails.
 
    .EXAMPLE
        PS> Test-HyperVEnabled
 
        Tests whether the Hyper-V optional feature is fully enabled.
 
    .INPUTS
        None. This function does not accept pipeline input.
 
    .OUTPUTS
        System.Boolean. Returns $true when Microsoft-Hyper-V-All is Enabled;
        otherwise, returns $false.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Version: 1.0.0
        Date: 2026-08-28
 
        Requires Windows and permission to query online optional features.
 
    .LINK
        Test-HyperVEnablePending
    #>

    [OutputType([bool])]
    param ()

    if (-not (Get-Command -Name 'Get-WindowsOptionalFeature' -ErrorAction SilentlyContinue)) {
        return $false
    }

    try {
        $feature = Get-WindowsOptionalFeature -Online -FeatureName 'Microsoft-Hyper-V-All' -ErrorAction Stop
        return ($feature.State -eq 'Enabled')
    }
    catch {
        return $false
    }
}