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.
Then modify the parameters on the below script with your details:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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:
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!
[twitter-follow screen_name=’singhprateik’ show_count=’yes’]
Prateek Singh
Related posts
14 Comments
Leave a ReplyCancel reply
Categories
Author of Books
Awards
Open Sourced Projects
Author at
Blog Roll
Mike F RobbinsDamien Van Robaeys
Stéphane van Gulick
Kevin Marquette
Adam Bertram
Stephanos Constantinou
Francois-Xavier Cat
Ravikanth Chaganti
Roman Levchenko
Blog Stats
- 1,132,192 People Reached
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
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
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.
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.
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
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
Thank you sir…..for now….I’ll get back to you in future..
Please try-
import-module servermanager
Excellent. One question. Is this script doable in Azure Cloud plataform?
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.
excelent work!!!!! but i need hide my password but i don’t know how can i do it, can you help me to change the script for asking password and not broke the script? thanks!!!!!!!!
Hi!
Thanks a lot for sharing this 🙂
Tho i have a question, can i filter to only find example DFS Roll or AD Service Roll that is installed on server from the *.txt file?
Best Regards
Pipe it directly to Excel using the ImportExcel module!
Good start script. I run something similar but use AD for source. Helps to use Test-WSMan before trying the invoke-command.
where is the script?