How to return true/false to Get-WindowsOptionalFeature on Windows 10
<p>I'm trying to check if a Windows Feature is installed or not, before install, to avoid reinstall.</p>

<p>I'm using this  to check:  </p>

<pre><code>function Check-WindowsFeature {
    [CmdletBinding()]
    param(
        [Parameter(Position=0,Mandatory=$true)] [string]$FeatureName 
    )  
  if((Get-WindowsOptionalFeature -FeatureName $FeatureName -Online) -Like "Enabled") {
        # $FeatureName is Installed
        # (simplified function to paste here)
    } else {
        # Install $FeatureName 
    }
  }
}
</code></pre>

<p>But "if" always return false, even when feature is installed.<br>
Example:  </p>

<pre><code>C:\&gt; (Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-All -Online) -Like "Enabled"
False

C:\&gt; Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-All -Online | ft -Property State
State
-----
Enabled
</code></pre>

<p>I already tried format as table, format as wide, filter with <code>-Property State</code>, output as string, match with regex, match with <code>-eq</code>and <code>contains</code> and none works.</p>

<p>Function get <code>$FeatureName</code> fine, 'cause install works.</p>

<p>How to make this work?</p>