private/Tests/Test-HyperVEnablePending.ps1

function Test-HyperVEnablePending {
    <#
    .SYNOPSIS
        Returns $true when the Hyper-V optional feature has been enabled
        (a restart may still be pending).
 
    .DESCRIPTION
        Returns $true for both 'Enabled' and 'EnablePending' states — the
        feature has been turned on but the machine may not yet have restarted.
        Use Test-WindowsOptionalFeatureEnabled when you need to confirm Hyper-V is fully
        operational without a pending restart.
 
        Returns $false when the feature is disabled, 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
    #>

    [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 'EnablePending')
    }
    catch {
        return $false
    }
}