No, there is not a way to make those cmdlets work on Windows 7.
While you really shouldn't be using Windows 7 anymore, you should still be able to get this information from WMI. I don't recall if the Get-CimInstnace
cmdlets were available on 7, so I'll use the Get-WmiObject
method:
Function Get-WmiWindowsOptionalFeatures {
[CmdletBinding()]
Param(
[string]$FeatureName,
[ValidateSet('Enabled', 'Disabled', 'Absent', 'Unknown', '1', '2', '3', '4')]
[string]$InstallState
)
Get-WmiObject Win32_OptionalFeature | Where-Object {
$feature = $_
$featureMatch = !$FeatureName -or ( $FeatureName -and $feature.Name -like $FeatureName )
$installStateMatch = switch ( $InstallState ) {
{ $_ -in 'Enabled', '1' } {
$feature.InstallState -eq 1
break
}
{ $_ -in 'Disabled', '2' } {
$feature.InstallState -eq 2
break
}
{ $_ -in 'Absent', '3' } {
$feature.InstallState -eq 3
break
}
{ $_ -in 'Unknown', '4' } {
$feature.InstallState -eq 4
break
}
default {
$true
break
}
}
$featureMatch -and $installStateMatch
} | Select-Object Name, Caption, Description, InstallDate, @{
Label = 'InstallState'
Expression = {
switch ( $_.InstallState ) {
1 {
'Enabled'
break
}
2 {
'Disabled'
break
}
3 {
'Absent'
break
}
4 {
'Unknown'
break
}
default {
$_.ToString()
break
}
}
}
}
}
This will give you back a nice operable object with the important fields which can be evaluated and operated upon. The class you have to inspect is Win32_OptionalFeatures
.
To use the function:
- No arguments: returns all features
-FeatureName
: returns features matching the Name
. Supports -like
patterns.
-InstallState
: returns features matching the InstallState
. Takes convenient strings or the numbered value as mapped below.
To understand the install state, here are the possible values for each (they are stored as a uint32
):
- Enabled
- Disabled
- Absent
- Unknown
Unfortunately, there is no way to use WMI to install the features, so you'll have to install them with dism.exe
.