title: How do you check to see if Hyper-V is enabled using PowerShell?
body: <p>I am trying to write a PowerShell script that checks the Windows Optional Features to see if Hyper-V is installed. However, my code is not working. Even when Hyper-V is disabled, the script outputs that it is already enabled.</p>
  
  <pre><code>#Requires -RunAsAdministrator
  
  # Get the Hyper-V feature and store it in $hyperv
  $hyperv = Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-All -Online
  
  # Check if Hyper-V is already enabled.
  if($hyperv.State = "Enabled") {
      Write-Host "Hyper-V is already enabled."
  } else {
      Write-Host "Hyper-V is disabled."
  }
  </code></pre>
  
  <p>There is no error when the code is run.</p>