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:


$domain= 'LABDOMAIN\Username'
$pass=ConvertTo-SecureString -String 'YourPassword' -AsPlainText -Force
$creds=New-Object System.Management.Automation.pscredential -ArgumentList $domain, $pass
(Get-Content D:\Servers.txt| `
Foreach{Invoke-Command -ComputerName $_ -Verbose -ScriptBlock{get-windowsfeature | `
Where-Object{$_.installed -eq $true -and $_.featuretype -eq 'Role'} |
select name, installed -ExcludeProperty subfeatures} -Credential $creds}) | `
Format-Table -Property Name, Installed, @{name='Server Name';expression={$_.pscomputername}} -AutoSize

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 [twitter-follow screen_name=’singhprateik’ show_count=’yes’]