如何使用 PowerShell 在 Windows 10 上启用 WCF 服务?

How to enable WCF Services on Windows 10 with PowerShell?

有人可以帮我在 Windows 10 上启用 WCF 服务吗?我尝试了下面列出的命令,但只启用了 WCF-TCP-PortSharing45。

Enable-WindowsOptionalFeature -Online -FeatureName WCF-Services45
Enable-WindowsOptionalFeature -Online -FeatureName WCF-HTTP-Activation45
Enable-WindowsOptionalFeature -Online -FeatureName WCF-TCP-Activation45
Enable-WindowsOptionalFeature -Online -FeatureName WCF-Pipe-Activation45
Enable-WindowsOptionalFeature -Online -FeatureName WCF-MSMQ-Activation45
Enable-WindowsOptionalFeature -Online -FeatureName WCF-TCP-PortSharing45

Windows 我电脑上的功能:

Get-WindowsOptionalFeature -Online | Where-Object {$_.State -like "Disabled" -and $_.FeatureName -like "*WCF*"} | % {Enable-WindowsOptionalFeature -Online -FeatureName $_.FeatureName -All}

这是为我做的。关键是 -All 标志:来自 MS documentation

Enables all parent features of the specified feature. If a parent feature is required for the specified feature to be enabled in the image, All will enable the parent and all of its default dependencies.

这就是 运行 对我来说你的上述命令失败的地方,错误消息是:

 "One or several parent features are disabled so current feature can not be enabled"

我的回答使用循环来获取每个可用的 WindowsOptionalFeature。此外,您可以简单地 运行 使用 -All 参数的上述命令,如下所示:

Enable-WindowsOptionalFeature -Online -FeatureName WCF-Services45 -All