Powershell : How to Retrieve List of Installed Roles on Servers in your Infrastructure


For documentation purpose or just to understand your environment better below script could be useful in order to fetch the list of roles installed on a list of servers.

First, prepare a list of servers in a notepad file and save it.

lab

Then modify the parameters on the below script with your details:

Once you’ll run the script you will get the list of server roles installed on each machine in the list this:

lab

You can Export the data into a excel file by piping the last cmdlet of the script into Export-CSV cmdlet.

PLEASE NOTE :  This Script just give you Installed Roles, Not the installed features. To include features as well in the results, please remove the -and $_.featuretype -eq ‘Role’ from the script

Hope you’ll find it useful, cheers!

signature 

 

Advertisements

10 thoughts on “Powershell : How to Retrieve List of Installed Roles on Servers in your Infrastructure

  1. I must say that your PS creations are wonderful and speaks of your expertise.

    when I am running this script I am able to get the installed roles and features on the local machine however, it is failing to give me the details of installed roles on remote machines;
    Quick reply will be much appreciated.
    Fails with below error:
    PS C:\> C:\Get-Installed_Roles_Feature.ps1
    The term ‘Get-WindowsFeature’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
    correct and try again.
    + CategoryInfo : ObjectNotFound: (Get-WindowsFeature:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
    + PSComputerName : DC1

    The term ‘Get-WindowsFeature’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
    correct and try again.
    + CategoryInfo : ObjectNotFound: (Get-WindowsFeature:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
    + PSComputerName : dc3

    Like

    1. Hi Abhishek, Please make sure you’ve Remote server administration tools [RSAT] available on the machine on which you tried to run the script. Here is the link to download that – http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=7887

      once installed do an –
      Import-Module before get-windowsFeature something like

      (Get-Content D:\Servers.txt| foreach{Invoke-Command -ComputerName $_ -Verbose -ScriptBlock{Import-Module servermanager;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}} -AutoSize

      Like

      1. Thank you very much for the reply…..
        I found that does not matter where I was running the scripts I was able to get the desired result only from 2012 onwards machines. The only machines that were failing to give result were 2008 R2 and below. I installed PS version 3 on them and now the same script is working fine. It seems that since PS v3 automatically imports the required modules that is why it started working with PS v3. However, my concern was that in Production I will not be allowed to do many changes. As per your suggestion do I need to install RSAT on the only machine on which we are running the script from or on other remote machines from where we are trying to fetch details.

        Like

        1. RSAT would be required on the remote machine. It would be an add on if you have PS updated in your prod ENV as well. but as work around you can anyways use WMI query, something like this –

          Get-WmiObject -class “Win32_ServerFeature” |select name

          which is supported by Win2008 onwards.

          Like

          1. Thank you for the information. It was helpful.
            I was from Microsoft background core troubleshooting team. Now I have joined other company and here less of troubleshooting and more of reports and scripts. I am trying to learn PS. I do not know c or C++.. But I want to be proficient in PS and especially automation. Any thing you can suggest about study materials. How to go about it. Some helpful tips

            Like

          2. For Powershell Automation, you can refer “Don Jones – Learn powershell in month of lunches” on youtube or “Powershell 3.0 : JumpStart ” on microsoft virtual academy. I think these two are more than sufficient

            Like

  2. However I am not able to fetch information about the Windows server 2008. We can easily fetch information of a remote computer using “windows-feature” cmdlet and from the error message I need to installed .net frame work to run this command remotely on windows 2008 server.

    Could you please guide me if there is any other way to do it without installing .net framework.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s