Detecting what Server Roles are installed on Windows Server 2008

I think there is always a nugget of information that inspires a blog.  This is the idea that inspired my blog.


By default, Windows Server 2008 has no server roles installed.  This isn’t intended to make you do more work (it’s a feature).  The goal is to be secure by default.  After the OS installed, you add the roles and features that that are needed.


So, from an application compatibility point of view, your application may require a role that isn’t installed by default.  There are two ways to programmatically query what roles and features are installed.



Using ServerManagerCmd


UPDATE: ServerManagerCmd is being deprecated.  It is recommended to use PowerShell cmdlets for Server Manager starting with R2 forward.


There’s a cool command line utility that has been added to Window Server 2008 called ServerManagerCmd.  ServerManagerCmd allows you to add, remove, and query roles and features. 


If you execute the following command:



> servermanagercmd.exe -query roles.xml


An XML file of all the roles and features installed will be created.  You could then parse that file to determine what roles and features are installed.  I was hoping to find something in the scripting repository to do this but couldn’t find anything.  Powershell would be a good option but remember… no features are installed by default.  Powershell and .NET 3.0 would need to be installed.  You could do that with servermanagercmd as well.


For example:



> servermanagercmd.exe -install Powershell


ServerManagerCmd is great for scripting but what if you want to do determine installed roles in your application’s installer? …or avoid lots of parsing in a script? ..or needing to install .NET and Powershell?  WMI is probably a better choice.


Using WMI

With Windows Server 2008, there is a new class in the WMI namespace \Root\cimv2 called Win32_ServerFeature.  This will allow you to use WMI to iterate through what roles and features are installed.  WMI is a very good option for determining in your installer if a prerequisite role is installed.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.