Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all Server Features/Roles in Powershell

Tags:

powershell

So I have the following code to output all features and roles installed:

Import-Module ServerManager
$Arr = Get-WindowsFeature | Where-Object {$_.Installed -match “True”} | Select-Object -Property Name
$loopCount = $Arr.Count
For($i=0; $i -le $loopCount; $i++) {
    Write-Host $Arr[$i]
}

However, the output is:

@{Name=Backup-Features}
@{Name=Backup}
@{Name=Backup-Tools}

How can I get rid of the @ and {}'s ?

like image 628
PnP Avatar asked Nov 01 '13 18:11

PnP


People also ask

How do I get a list of Windows features in PowerShell?

To get the windows features and roles available or installed using PowerShell, you need to use the Get-WIndowsFeature cmdlet. That is obvious that Windows features and roles are available only on the server operating systems not on the client operating system.

How do I see installed roles and features?

The get-windowsfeature PowerShell command will get information about installed and available features and roles. As you can see in the screenshot above the command gets the display name, name, and the install state of services and roles on my local computer.


2 Answers

Use Select -ExpandProperty Name instead of Select -Property Name

Alternatively and also, I recommend using Foreach-Object instead of a C-style for loop.

Import-Module ServerManager
Get-WindowsFeature | 
    Where-Object {$_.Installed -match “True”} | 
    Select-Object -ExpandProperty Name |
    Write-Host

Or

Import-Module ServerManager
Get-WindowsFeature | 
    Where-Object {$_.Installed -match “True”} | 
    ForEach-Object {
        $_.Name | Write-Host
    }
like image 154
Eris Avatar answered Oct 23 '22 04:10

Eris


How about a nice one liner?

Get-WindowsFeature | ? {$_.Installed -match “True”} | Select -exp Name
like image 24
RandyC Avatar answered Oct 23 '22 03:10

RandyC