Reputation: 8953
In Windows 10, you can "Turn windows features on and off" in the control panel; you see a screen as such:
Let's say I want to select IIS 6 WMI Compatibility by using the Enable-WindowsOptionalFeature
command in powershell.
If I run :
Get-WindowsOptionalFeature "IIS 6 WMI Compatibility"
I get this error:
Get-WindowsOptionalFeature : A positional parameter cannot be found that accepts argument 'IIS 6 WMI Compatibility'.
At line:1 char:1
+ Get-WindowsOptionalFeature "IIS 6 WMI Compatibility"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-WindowsOptionalFeature], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Dism.Commands.GetWindowsOptionalFeatureCommand
Question
How do I map the names of these features to the PowerShell command?
End Goal
The end goal is to automate setting up a new developer and his machine.
Upvotes: 7
Views: 15259
Reputation: 16126
Good you found a answer that works for you, but...
Yet, you don't need a function to use wildcards. Just do this...
Get-WmiObject -Class $Win32_OperatingSystem
SystemDirectory : C:\WINDOWS\system32
Organization :
BuildNumber : 17134
RegisteredUser :
SerialNumber : 00330-50027-66869-AAOEM
Version : 10.0.17134
$PSVersionTable
Name Value
---- -----
PSVersion 5.1.17134.165
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0, 5.0, 5.1.17134.165}
BuildVersion 10.0.17134.165
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
# List features all
(Get-WindowsOptionalFeature -Online -FeatureName '*') | Format-Table -Autosize
(Get-WindowsOptionalFeature -Online -FeatureName '*').Count
144
# List features for IIS
(Get-WindowsOptionalFeature -Online -FeatureName '*IIS*').Count
54
# List features for wmi
(Get-WindowsOptionalFeature -Online -FeatureName '*wmi*').Count
2
# List features for IIS or wmi
(Get-WindowsOptionalFeature -Online -FeatureName '*iis*|*wmi*').Count
55
# List features for IIS or wmi or hyperv
(Get-WindowsOptionalFeature -Online -FeatureName '*iis*|*wmi*|*hyper*').Count
63
Upvotes: 7
Reputation: 8953
I figured it out.
The code below is used to find the feature by using wildcards
$features = Get-WindowsOptionalFeature -Online
Write-Host ('There are ' + $features.Count + ' Windows features available') -ForegroundColor Green
foreach($feature in $features)
{
if($feature.FeatureName -like "*IIS*WMI*") # wildcard search
{
$feature
}
}
The code above returns this:
There are 170 Windows features available
FeatureName : IIS-WMICompatibility
State : Disabled
Therefore, to enable the feature you can run:
$feature = Get-WindowsOptionalFeature -Online -FeatureName 'IIS-WMICompatibility'
Enable-WindowsOptionalFeature $feature -Online
Note: you have to run Enable-WindowsOptionalFeature
as admin...
You can verify that it was enabled by running this:
(Get-WindowsOptionalFeature -Online -FeatureName 'IIS-WMICompatibility').State
Upvotes: 5