Get list of installed features and roles on all domain servers - Powershell

Naveen Kumar 21 Reputation points

Get list of installed features and roles on all domain servers - Powershell

Get-ADComputer -Filter 'operatingsystem -like "server" -and enabled -eq "true"' `
-Properties Name,Operatingsystem,OperatingSystemVersion,IPv4Address |
Sort-Object -Property Operatingsystem |
Select-Object -Property Name,Operatingsystem,OperatingSystemVersion,IPv4Address|Export-Csv c:\temp\allservers.csv -NoTypeInformation

above command is giving servers name, which looks good but when i run below command it gives me only one computer (last name in allservers.csv) role and feature info , i need all servers list of installed features and roles

$lists=Import-Csv c:\temp\allservers1.csv
foreach($list in $lists){
Get-WindowsFeature -ComputerName $ | Where-Object {$_. installstate -eq "installed"} |
select Name,Installstate | export-csv c:\temp\pelicanservers1-roles.csv -NoTypeInformation

above command should give role and feature info for all servers which is mentioned in allservers.csv and export file pelicanservers1-roles.csv should have servers name as well for which role and feature is associated with.

Thanks in advance for help!

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,208 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,454 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Victor Delgado 6 Reputation points

    Here you go were almost there - you just needed to get your server name into a form where it could be output using calculated values

    # =====================================================================================================================================  
    # AUTHOR: yournamehere  
    # LAST UPDATE  : mm/dd/yyyy  
    # COMMENT: Script to search all AD servers for their installed roles and features and output the info to a csv  
    # =====================================================================================================================================  
    #Build our source file in case it doesn't already exist or is out of date and pull in the result  
    import-module activedirectory  
    Get-ADComputer -Filter {OperatingSystem -Like "Windows Server*"} | `  
    Select-Object -ExpandProperty Name | `  
    Out-file "\\yoursevername\c$\All_Servers.txt"  
    #Pull your results back in  
    $computers= get-content '\\yoursevername\c$\All_Servers.txt'  
    #delete the existing file we're about to created if it's there since we're running an append...otherwise, we'd need to manually delete the file before each script run  
    del "\\yoursevername\c$\All_Servers_Installed_Roles_and_Features.csv"  
    #Iterate through each server and pull desired info - we have to use a calculated value to prepend the server name to each output row since Get-WindowsFeature doesn't supply it  
    foreach($computer in $computers){  
      Get-WindowsFeature -ComputerName $computer | Where-Object {$_. installstate -eq "installed"} |  
      Select @{Name='Server';Expression={$computer}}, DisplayName, Name, FeatureType, Parent, Path |   
      export-csv "\\yoursevername\c$\All_Servers_Installed_Roles_and_Features.csv" -Append -NoTypeInformation -Encoding UTF8  
    1 person found this answer helpful.

  2. Anonymous

    You can follow along here.

    --please don't forget to upvote and Accept as answer if the reply is helpful--

  3. Limitless Technology 39,496 Reputation points


    Thank you for your question and reaching out.
    I can understand you are having some issues related to get installed features and roles on all servers.

    You can try below powershell code block assimung that WinRM and RPC is enabled.

    (Get-Content .\Servers.txt| foreach{Invoke-Command -ComputerName $_ -Verbose -ScriptBlock{get-windowsfeature `
    | ?{$_.installed -eq $true -and $_.featuretype -eq 'Role'} | select name, installed -ExcludeProperty subfeatures} -Credential $creds}) 
    `| ft -Property Name, Installed, @{name='Server Name';expression={$_.pscomputername}} | Export-Csv info.csv -NoTypeInformation

    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments