Formatting output get-windowsfeature for a report


I am trying to create a table in a report in CSV that I can copy and paste to a Word table for a report of what is installed on a machine in terms of roles and features.

I see that without no selection of any property I get a nice indented output like this one:

Get-WindowsFeature | Where-Object {$_. installstate -eq "installed"}

Display Name                                            Name                       Install State
------------                                            ----                       -------------
[X] Servicios de archivos y almacenamiento              FileAndStorage-Services        Installed
  [X] Servicios de almacenamiento                     Storage-Services               Installed
[X] CaracterĂ­sticas de .NET Framework 4.6               NET-Framework-45-Fea...        Installed
  [X] .NET Framework 4.6                              NET-Framework-45-Core          Installed
  [X] Servicios WCF                                   NET-WCF-Services45             Installed
      [X] Uso compartido de puertos TCP               NET-WCF-TCP-PortShar...        Installed
[X] CaracterĂ­sticas de Windows Defender                 Windows-Defender-Fea...        Installed
  [X] Windows Defender                                Windows-Defender               Installed
[X] Compatibilidad con el protocolo para compartir a... FS-SMB1                        Installed
[X] Compatibilidad con WoW64                            WoW64-Support                  Installed
[X] Windows PowerShell                                  PowerShellRoot                 Installed
  [X] Windows PowerShell 5.1                          PowerShell                     Installed

If I select the property displayname I lose the and the indentation of the hierarchy. In my report I want to show that hierarchy through the indentation (if possible replacing with tabs).

How can I achieve that?

@miguel_gonz Welcome to forums.

IMO, these checkboxes are not directly given by Get-windowsFeature but added by formatting subsystem and cannot be made available directly to a csv/excel file. Since you are already filtering out for only installed, its obvious that all the items in the CSV are installed. So a special indication is actually not required.

You can create a new property based on installed status and this new property can be a column in your csv. You can Calculate a property for that.

Get-WindowsFeature | Where-Object {$_. installstate -eq "installed"} |
Select-Object -Property Name, 'Display Name', @{E='Yes';L='Status'}

Thanks for the prompt reply. I think I haven´t myself understood.

I want to display only “Display Name” property with indentation (grouped exactly as shown before), so something like this:

 Servicios de archivos y almacenamiento              
   Servicios de almacenamiento                     
 CaracterĂ­sticas de .NET Framework 4.6               
   .NET Framework 4.6                              
   Servicios WCF                                   
       Uso compartido de puertos TCP              
 CaracterĂ­sticas de Windows Defender                 
   Windows Defender                                
 Compatibilidad con el protocolo para compartir a... 
 Compatibilidad con WoW64                            
Windows PowerShell                                  
   Windows PowerShell 5.1 

Even the spaces are added by formatting subsystem.

Below is a post I wrote few years back on it if you want to understand it more.

Learn-PowerShel l| Rule the World Using A OneLiner: Hidden Formatting in PowerShell (

Many thanks for pointing me to the right direction.

For the sake of completeness I share a basic code I used following the info you shared:

$roles= Get-WindowsFeature | Where-Object {$_. installstate -eq "installed"}

foreach ($element in $roles) {
	for ($i=$element.Depth; $i -gt 1; $i--)
 	   $indent += "    "
	$indent+ $element.DisplayName
1 Like