Struggling with get-windowsfeature output

This topic contains 11 replies, has 3 voices, and was last updated by  Norm Long 1 week, 6 days ago.

  • Author
    Posts
  • #98511

    Norm Long
    Participant

    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

  • #98514

    Sam Boutros
    Participant

    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 
    
    • #98518

      JohnM
      Participant

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

    • #98521

      Sam Boutros
      Participant

      Yep, left over from debugging, fixing..

  • #98515

    JohnM
    Participant

    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!

  • #98529

    Norm Long
    Participant

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

  • #98530

    Norm Long
    Participant

    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

  • #98536

    Norm Long
    Participant

    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

    • #98568

      Sam Boutros
      Participant

      no just send cookies.. lol

    • #98569

      Sam Boutros
      Participant

      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
      
    • #98571

      Sam Boutros
      Participant

      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
      }
      
  • #98577

    Norm Long
    Participant

    Sam;
    Thank you for the additional input....

    Norm

You must be logged in to reply to this topic.