Question:
So I have the following code to output all features and roles installed:
1 2 3 4 5 6 7 |
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:
1 2 3 4 |
@{Name=Backup-Features} @{Name=Backup} @{Name=Backup-Tools} |
How can I get rid of the @
and {}
‘s ?
Answer:
Use Select -ExpandProperty Name
instead of Select -Property Name
Alternatively and also, I recommend using Foreach-Object instead of a C-style for loop.
1 2 3 4 5 6 |
Import-Module ServerManager Get-WindowsFeature | Where-Object {$_.Installed -match “True”} | Select-Object -ExpandProperty Name | Write-Host |
Or
1 2 3 4 5 6 7 |
Import-Module ServerManager Get-WindowsFeature | Where-Object {$_.Installed -match “True”} | ForEach-Object { $_.Name | Write-Host } |