PowerShell中的FilterScript

时间:2015-01-28 14:16:14

标签: powershell powershell-v3.0

我正在使用Windows Server 2012 R2与PowerShell v5,我偶然发现了一些我不理解的PowerShell行为。

以下行正常工作并按预期返回结果:

Get-WindowsFeature | where -Property "InstallState" -eq "Installed"

这正常工作并返回上一个结果:

Get-WindowsFeature | where {$_.Installed}

以下是 NOT 正在工作,即使它应该:

Get-WindowsFeature | where {$_.Available}

但是这个有效:

Get-WindowsFeature | where -Property "InstallState" -eq "Available"

我在Windows 7上也看到了与PowerShell v3相同的行为。

请向我解释一下。

1 个答案:

答案 0 :(得分:2)

Get-WindowsFeature | Get-Member -MemberType Property

TypeName: Microsoft.Windows.ServerManager.Commands.Feature

Name                      MemberType Definition                                                                                       
----                      ---------- ----------                                                                                       
AdditionalInfo            Property   hashtable AdditionalInfo {get;}                                                                  
BestPracticesModelId      Property   string BestPracticesModelId {get;}                                                               
DependsOn                 Property   string[] DependsOn {get;}                                                                        
Depth                     Property   int Depth {get;}                                                                                 
Description               Property   string Description {get;}                                                                        
DisplayName               Property   string DisplayName {get;}                                                                        
EventQuery                Property   string EventQuery {get;}                                                                         
FeatureType               Property   string FeatureType {get;}                                                                        
Installed                 Property   bool Installed {get;}                                                                            
InstallState              Property   Microsoft.Windows.ServerManager.Commands.InstallState InstallState {get;}                        
Name                      Property   string Name {get;}                                                                               
Notification              Property   Microsoft.Windows.ServerManager.ServerComponentManager.Internal.Notification[] Notification {g...
Parent                    Property   string Parent {get;}                                                                             
Path                      Property   string Path {get;}                                                                               
PostConfigurationNeeded   Property   bool PostConfigurationNeeded {get;}                                                              
ServerComponentDescriptor Property   psobject ServerComponentDescriptor {get;}                                                        
SubFeatures               Property   string[] SubFeatures {get;}                                                                      
SystemService             Property   string[] SystemService {get;}    

没有“可用”属性。