Home » PowerShell » Use PowerShell to Check if Hyper-V is Enabled in Windows

Use PowerShell to Check if Hyper-V is Enabled in Windows

Use the Get-WindowsOptionalFeature cmdlet in PowerShell with -FeatureName to specify ‘Hyper-V’ and get the details about the feature Hyper-V. You can use the if condition to check if Hyper-V is enabled.

The Get-WindowsOptionalFeature cmdlet in PowerShell is used to get a list of all of the optional features in the running operating system.

In this article, we will discuss how to use the PowerShell Get-WindowsOptionalFeature cmdlet to check if Hyper-V is enabled.

PowerShell Check if Hyper-V is Enabled

You can use the following PowerShell script to check if Hyper-V is enabled.

# Check if Hyper-V is enabled

$feature = "Hyper-V"

# Get the status of the Hyper-V feature
$status = Get-WindowsOptionalFeature -Online -FeatureName $feature

# Check if the status is enabled
if ($status.State -eq "Enabled") {
    Write-Host "Hyper-V is enabled."
} else {
    Write-Host "Hyper-V is not enabled."
}

In the above PowerShell script, the $feature variable stores the name of the ‘Hyper-V’ feature. The Get-WindowsOptionalFeature cmdlet in PowerShell uses the parameters -Online and -FeatureName to get the details of the Hyper-V feature. Finally, it checks if the status is enabled and prints a message to the console accordingly.

The output of the above PowerShell script to check Hyper-V is enabled on the running operating system is:

Hyper-V is enabled.

How to Enable Hyper-V Feature

You can use the Enable-WindowsOptionalFeature cmdlet in PowerShell to enable the Hyper-V feature on the running operating system.

Enable-WindowsOptionalFeature -Online -FeatureName Hyper-V

In the above PowerShell script, the Enable-WindowsOptionalFeature cmdlet uses the parameter -FeatureName to specify the Hyper-V feature and enable the Hyper-V feature. You will need to restart your computer, after the computer restarts, Hyper-V will be enabled.

Conclusion

I hope the above article on how to check if the hyper-v is enabled using PowerShell is helpful to you.

The Get-WindowsOptionalFeature cmdlet in PowerShell is used to get details about the feature and to check their status if they are either enabled or disabled.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.