WindowsOptionalFeature

WindowsOptionalFeature

在Windows 10中,您可以在控制面板中“打开和关闭Windows功能” ;您会看到这样的屏幕:
windows - Powershell-如何使用Get-WindowsOptionalFeature命令来 "Turn Windows Features On and Off"-LMLPHP

假设我想通过在Powershell中使用Enable-WindowsOptionalFeature命令选择 IIS 6 WMI兼容性

如果我运行:
Get-WindowsOptionalFeature "IIS 6 WMI Compatibility"
我收到此错误:

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

问题

如何将这些功能的名称映射到PowerShell命令?

最终目标

最终目标是自动设置新的开发人员和他的机器。

最佳答案

很好,您找到了一个适合您的答案,但是...

但是,您不需要使用通配符的功能。只是做这个...

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

关于windows - Powershell-如何使用Get-WindowsOptionalFeature命令来 "Turn Windows Features On and Off",我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51789863/

10-10 11:58