Struggling with get-windowsfeature output

Trying and have failed to figure out a way to get the following output from get-windowsfeature:

Server Name name
NLapp077 NET-Framework-Features
NET-Framework-Core
NET-Framework-45-Features
NET-Framework-45-Core
NET-Framework-45-ASPNET

This gives the feature name but no server name:
Get-WindowsFeature -ComputerName nlapp177 | where-object {$.Installed -match “True”} | Select Name | Where-Object {$.Name -like “Net-Framework*”}

This gives me server name but no feature name:
get-content d:\powershell_temp\servers.txt | where-object { Get-WindowsFeature -Name “Net-Framework*” -ComputerName $_ | Where Installed }

Been trying to figure out how to put the two together to get the desired output but alas not smart enough to make it work.

In and all input would be appreciated.

Norm

Please review this script. It will gather list of installed features on the listed computers. Ask me about any part of the code that needs to be explained

$ComputerList = @('Computer1','Computer2')

$myOutput = foreach ($ComputerName in $ComputerList) {
    $FeatureList = Get-WindowsFeature -ComputerName $ComputerName | where Installed | select Name,DisplayName
    foreach ($FeatureName in $FeatureList) {
        [PSCustomObject][Ordered]@{
            ComputerName = $ComputerName
            FeatureName  = $FeatureName.Name
            DisplayName  = $FeatureName.DisplayName
        }
    }
}

$myOutput | FT -a 
$myOutput | Out-GridView
$myOutput | Export-Csv .\FeatureList.csv -NoType 

Try something like this on one computer and see what properties are available to your version of PowerShell.

(Get-WindowsFeature  | where-object {$_.Installed -match “True” -AND $_.Name -like "Net-Framework*"}) | format-list -property *

Use Select-Object to choose the properties you want. I suspect the computername, or PSComputerName will be one of the available properties. Then you can work on making this command work for multiple servers. Good Luck!

Not sure $env:COMPUTERNAME belongs in the script from Sam. Should be $ComputerName.

Yep, left over from debugging, fixing…

Hello John;
Yeah tired something similar, sadly there is no computer name, hence my opportunity.
Thank you for taking the time to respond
Norm

Hello Sam;
Your response works except I’m only looking for the Net-framework feature, would appreciate your input on how to modify your script accordingly. Also found out get-windowsfeature does not work for 2008R2 note the following, oh well will figure out something else for 2008R2.

Get-WindowsFeature : The request could not be processed. Verify that you are running the command targeted at a server that is running Windows Server 2012.
At line:4 char:20

  • … $FeatureList = Get-WindowsFeature -ComputerName $ComputerName | where …
  •                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : DeviceError: (Microsoft.Manag…rDetailsHandle):CimException) [Get-WindowsFeature], Exception
    • FullyQualifiedErrorId : UnSupportedTargetDevice,Microsoft.Windows.ServerManager.Commands.GetWindowsFeatureCommand

Norm

Hello Sam;
Got your script to work for only .net

$ComputerList = @(‘fwapp177’,‘fwts012’)

$myOutput = foreach ($ComputerName in $ComputerList) {
$FeatureList = Get-WindowsFeature -ComputerName $ComputerName | where Installed | select Name,DisplayName | where {$_.DisplayName -like “.Net Framework*”}
foreach ($FeatureName in $FeatureList) {
[PSCustomObject][Ordered]@{
ComputerName = $ComputerName
FeatureName = $FeatureName.Name
DisplayName = $FeatureName.DisplayName
}
}
}

$myOutput | FT -a
$myOutput | Out-GridView
$myOutput | Export-Csv d:\powershell_temp\FeatureList.csv -NoType

Thanks alot for your script. Is there point assignment for this forum?

Norm

no just send cookies… lol

I would filter the $FeatureList line like this:

    $FeatureList = Get-WindowsFeature -ComputerName $ComputerName | 
        where { $PSItem.Installed -and $PSItem.Name -Match 'Net-Framework' } | select Name , DisplayName

or if you want to do it the Jeff Hicks way (all in a single line):

foreach ($ComputerName in @('Computer1','Computer2')) { 
    Get-WindowsFeature -ComputerName $ComputerName | 
        where { $PSItem.Installed -and $PSItem.Name -Match 'Net-Framework' } | 
            select @{name='ComputerName';e={ $ComputerName }}, Name , DisplayName
}

Sam;
Thank you for the additional input…

Norm