private/Tests/Test-HyperVEnabled.ps1

function Test-HyperVEnabled {
    <#
    .SYNOPSIS
        Returns $true when the Hyper-V optional feature is fully enabled and
        no system restart is required before it can be used.
 
    .DESCRIPTION
        Returns $true only when the feature state is 'Enabled' (not
        'EnablePending'). Use Test-HyperVEnabled if you only need to know
        whether Hyper-V has been turned on regardless of restart status.
 
        Returns $false when the feature is disabled, pending a restart,
        when Get-WindowsOptionalFeature is unavailable, or when the query fails.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Requires: Windows, Administrator rights (Get-WindowsOptionalFeature -Online).
        Feature name: Microsoft-Hyper-V-All
 
    Dependencies: None
    #>

    [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
    }
}