I am working with Windows Server 2016.
The PowerShell's Get-WindowsFeature cmdlet gives its output in 3 fields: Display Name, Name and Install State. As per documentation I can filter on Name field but I want to filter on Display Name field. How can I do that?
Also I can see there is hierarchy some times in values of Display Name field. For example .NET Framework 3.5 Features has 3 child items. I want to be able to filter on .NET Framework 3.5 Features Display Name field and can also see its child items. How can I do that?
Add a comment
|
3 Answers
You can use Where-Object and -like or -match
Get-WindowsFeature | Where-Object displayname -like '*framework 3.5*'
Get-WindowsFeature | Where-Object displayname -match 'framework 3\.5'
Even though it shows Display Name in the formatted output, it's actually DisplayName as the property name. You can see all its properties by using Get-Member
Get-WindowsFeature | Get-Member
2 Comments
Theo
Actually, the
-match uses regex, so you should escape the dot (or any other character that has special meaning in regex) by prefixing it with a backslash.Doug Maurer
You’re absolutely right. My test was just with “framework”. Good looking out Theo.