Zend certified PHP/Magento developer

How can I display a feature list with its subfeatures using Get-WindowsFeature in Powershell?

I’m using Hyper-V Server 2019. (This is a free Windows Server 2019 Core package with the Hyper-V role installed. It’s completely text-based by default – there’s no GUI desktop as with regular Windows Server packages, excepting with 3rd party solutions that aren’t part of this question.)

Many instructions for setting up various things on a server assume that a graphical tool is available. For example, the article Prepare your environment for Windows Admin Center shows how to perform Step 2: Enable File Server Role using the graphical tool normally available in other versions of Windows Server. Very few instructions include the Powershell method for doing things.

I have learned to use Powershell “cmdlets” to do various things, but I’m stuck on Step 2 above. I can figure out, I think, how to install the feature I need; however, for future reference, I want to be able to display the items I’m interested in. So…

To show a list of all features, I can enter Get-WindowsFeature. That, of course, brings up a long, scrolling list!

I can see by the diagram in the instructions that I need to see what’s installed under “File and Storage Services”. So, I do this:

Get-WindowsFeature | where {$_.InstallState -eq "Installed"}

(or, alternatively: Get-WindowsFeature | where Installed)

In Powershell 5.1, this returns:

Get-WindowsFeature: Installed Items List

I can add a Select-Object pipe with the property SubFeatures and get this:

Get-WindowsFeature: Installed Items List With SubFeatures

But, what I really want is like the first image, but restricted to the “File and Storage Services” section and all of its SubFeatures, regardless of the InstallState value.

I have seen an -ExpandProperty parameter used with array-type results, but adding that anywhere in the cmdlet just gives me an error about that parameter not being available or that the SubFeatures property is not available. But…

Get-WindowsFeature | Get-Member shows the property as follows:

SubFeatures Property string[] SubFeatures {get;}

I have tried the following with the -ExpandProperty parameter:

Get-WindowsFeature | where {$_.InstallState -eq "Installed"} | Select-Object -ExpandProperty DisplayName, Name, InstallState, SubFeatures

Get-WindowsFeature | where {$_.InstallState -eq "Installed"} | Select-Object DisplayName, Name, InstallState, -ExpandProperty SubFeatures

Get-WindowsFeature | where {$_.InstallState -eq "Installed"} | Select-Object DisplayName, Name, InstallState | Select-Object -ExpandProperty SubFeatures

Note: the only reason I used the InstallState on these was so that I didn’t get a huge scrolling result. I was experimenting with getting the SubFeatures property before diving into how to get just the one “File and Storage Services” section, since I think that is going to require that I get the SubFeatures figured out first… Hmm…

Also, as an aside: Powershell 7 has a Display Name field in the output; however, it’s blank. Only the Name and Install State fields have content. Interestingly, I can get the info by specifying it: Get-WindowsFeature | where Installed | Select-Object DisplayName, Name, InstallState, but it doesn’t have the nice little [X] markers 😉

Either way, what I’m looking for is how to get a specific section (File and Storage Services here) and its expanded SubFeatures property, so I can easily see what’s installed or available for that section using Powershell.