2

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.

Oh, and to be clear, I did try Get-WindowsFeature -Name FileAndStorage-Services, which returned only that one item (without its SubFeatures):

Get-WindowsFeature shows only one service


This is the first several lines of my output if I use simply Get-WindowsFeature, including the File and Storage Services section:

First several lines of Get-WindowsFeature output

leanne
  • 571
  • 5
  • 11

1 Answers1

3

To obtain the SubFeatures as output while querying FileAndStorage-Services, you can utilize the parent feature's Name property. By dynamically generating a list of its associated SubFeatures, you can ensure they are also included in the listing.

PowerShell

$FeatureName = "FileAndStorage-Services";
$subFeatures = (Get-WindowsFeature -Name $FeatureName | Select-Object SubFeatures).SubFeatures;
$subFeatures = $subFeatures+(Get-WindowsFeature -Name $subFeatures | Select-Object SubFeatures).SubFeatures;
$combineFeatures = "$($FeatureName)|$($subFeatures -join "|")";
Get-WindowsFeature | Where-Object {$_.Name -match $combineFeatures};

Output

Display Name                                            Name                       Install State
------------                                            ----                       -------------
[X] File and Storage Services                           FileAndStorage-Services        Installed
    [X] File and iSCSI Services                         File-Services                  Installed
        [X] File Server                                 FS-FileServer                  Installed
        [ ] BranchCache for Network Files               FS-BranchCache                 Available
        [ ] Data Deduplication                          FS-Data-Deduplication          Available
        [X] DFS Namespaces                              FS-DFS-Namespace               Installed
        [X] DFS Replication                             FS-DFS-Replication             Installed
        [ ] File Server Resource Manager                FS-Resource-Manager            Available
        [ ] File Server VSS Agent Service               FS-VSS-Agent                   Available
        [ ] iSCSI Target Server                         FS-iSCSITarget-Server          Available
        [ ] iSCSI Target Storage Provider (VDS and V... iSCSITarget-VSS-VDS            Available
        [ ] Server for NFS                              FS-NFS-Service                 Available
        [ ] Work Folders                                FS-SyncShareService            Available
    [X] Storage Services                                Storage-Services               Installed
        [X] File Services Tools                         RSAT-File-Services             Installed

More Detail

Executing this operation will unveil the values of the SubFeatures. In certain cases, employing the Select * approach can be particularly advantageous, as demonstrated in the output below.

Get-WindowsFeature -Name $FeatureName | Select-Object *;

The remaining components are trivial, so I've provided a supporting resources section that you can explore for further learning, should you be interested or find the need to dig deeper.

Output

Name                      : FileAndStorage-Services
DisplayName               : File and Storage Services
Description               : File and Storage Services includes services that are always installed, as well as functionality that you can install to help manage file servers and 
                            storage.
Installed                 : True
InstallState              : Installed
FeatureType               : Role
Path                      : File and Storage Services
Depth                     : 1
DependsOn                 : {}
Parent                    : 
ServerComponentDescriptor : ServerComponent_FileAndStorage_Services
SubFeatures               : {File-Services, Storage-Services}
SystemService             : {}
Notification              : {}
BestPracticesModelId      : Microsoft/Windows/FileServices
EventQuery                : FileServer.Events.xml
PostConfigurationNeeded   : False
AdditionalInfo            : {MajorVersion, MinorVersion, NumericId, InstallName}

Supporting Resources

Vomit IT - Chunky Mess Style
  • 40,038
  • 27
  • 84
  • 117
  • @leanne ... I ran this right on Windows Server 2019 to get the desired output using PowerShell version 5.1. Happy to clarify further or on any of the other trivial logic I used to get the desired output, just let me me know. – Vomit IT - Chunky Mess Style Aug 24 '23 at 23:20
  • Thanks so much for the answer! I appreciate the depth of information! Sadly, however... I tried the code in your answer, both line-by-line and as a script. The result looked identical to your output - except the last line (with `File Services Tools`) is not present. Also, I know there are 'children' under `File and iSCSI Services`, too. Am I missing something else? – leanne Aug 25 '23 at 01:34
  • I also tried my own idea like this: `Get-WindowsFeature | where {$_.Name -eq "FileAndStorage-Services" -or $_.Parent -eq "FileAndStorage-Services"}`. It gave me the same output as your script did: identical to your output except with the last line missing – leanne Aug 25 '23 at 01:36
  • Updated my question with the first several lines of my `Get-WindowsFeature` call. Seems like I don't have the `File Services Tools` under `Storage Services`; however, I do have a `File Server` entry under `File and iSCSI Services`. So... FWIW... – leanne Aug 25 '23 at 01:48
  • 1
    @leanne Oh I see what's up, the subfeatures have their own subfeatures. I worked it out, and about to edit answer with a new line of code, please refresh your screen to see the update in about 5 minutes or less. Let me know if this gets you all the detail you are after. I thought you meant only the subfeatures listed for `FileAndStorage-Services` only but this all makes sense. Thank you! – Vomit IT - Chunky Mess Style Aug 25 '23 at 12:29