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 ?
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.
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.
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
}
How about a nice one liner?
Get-WindowsFeature | ? {$_.Installed -match “True”} | Select -exp Name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With