powershell中的where-object

我怎么能把这两个人分开呢?

Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*|`
Where-Object {$_.displayname -like "*Database Engine Services*" } |  Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |Format-Table -AutoSize

Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |  Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Where-Object {($_.displayname -like "*Engagement*")  } |`
 Format-Table –AutoSize 

最佳答案 我使用RegEx方法将Where-Object过滤压缩到单个实例,但您也可以使用-OR将它带入单个实例.此外,无需将Select-Object作为Format-Table执行,因为只需使用Format-Table即可指定要显示的属性.

Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {
    $_.DisplayName -match '^Database Engine Services|Engagement'
} | Format-Table DisplayName, DisplayVersion, Publisher, InstallDate -AutoSize

以下是使用-OR和-LIKE语句的替代方法:

Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {
    $_.DisplayName -LIKE 'Database Engine Services*' -OR $_.DisplayName -LIKE '*Engagement*'
} | Format-Table DisplayName, DisplayVersion, Publisher, InstallDate -AutoSize
点赞