关于where-object cmdlet

我刚刚开始使用PowerShell,我有一个关于这个命令的问题:

Get-WindowsFeature | where installed 

它返回我的function安装,现在我想所有的function删除或可用,但是当我replace“已安装”删除/可用,它没有显示我什么,为什么?

多谢你们!

在你的例子中,你检查的Installed是一个布尔属性。 这是真的或假的,你正在检查所有的对象,它是$TrueRemovedAvailableInstallState可能值,而不是直接属性。

你可以看到这个

 PS> Get-Windowsfeature | Get-Member TypeName: Microsoft.Windows.ServerManager.Commands.Feature Name MemberType Definition ---- ---------- ---------- <extra removed> Installed Property bool Installed {get;} InstallState Property Microsoft.Windows.ServerManager.Commands.InstallState InstallState {get;} <extra removed> 

尝试其中之一:

 Get-Windowsfeature | Where-Object { -not $_.Installed } Get-WindowsFeature | Where-Object { $_.InstallState -eq "Available" } Get-WindowsFeature | Where-Object { $_.InstallState -eq "Removed" }