private/Test-HyperVEnablePending.ps1
|
function Test-HyperVEnablePending { <# .SYNOPSIS Tests whether the Hyper-V optional feature state is EnablePending .DESCRIPTION Queries the Microsoft-Hyper-V-All optional feature in the running Windows installation. Returns $true only when its state is EnablePending. Returns $false for all other states, when Get-WindowsOptionalFeature is unavailable, or when the query fails. .EXAMPLE PS> Test-HyperVEnablePending Tests whether enabling Hyper-V is pending a system restart. .INPUTS None. This function does not accept pipeline input. .OUTPUTS System.Boolean. Returns $true when Microsoft-Hyper-V-All is EnablePending; 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-HyperVEnabled #> [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 } } |