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.
Read the complete article on my new website RidiCurious.com
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
LikeLike
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
LikeLike
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.
LikeLike
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.
LikeLike
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
LikeLike
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
LikeLike
Thank you sir…..for now….I’ll get back to you in future..
LikeLiked by 1 person
Please try-
import-module servermanager
LikeLike
Excellent. One question. Is this script doable in Azure Cloud plataform?
LikeLike
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.
LikeLike
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!!!!!!!!
LikeLike
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
LikeLike
Well You can run this to get Info..
Get-WindowsFeature | Where-Object {$_. installstate -eq “installed”} | Format-List Name,Installstate | more
LikeLike