2

I have been asked to specify the features which are installed on a production web server so a replica test environment can be created.

I could point and click my way to the solution but I am curious as to how this could be done through a script. Powershell or WMI spring to mind. The report should show all the key system features which are installed along with version numbers. Ideally it would also give some information about the installed operating system

0

5 Answers 5

3

Win32_ServerFeature is what you are looking for if you must script it with WMI. It is only with Windows 2008. Example VBScript code from the MSDN link follows.

strComputer = "FABRIKAM"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFeatureList = objWMIService.ExecQuery _
    ("SELECT Name FROM Win32_ServerFeature")

For Each objFeature In colFeatureList
   WScript.Echo objFeature.Name

Next
3

In Server 2008 R2, it's very simple:

Import-Module ServerManager
Get-WindowsFeature

Hope this helps

1

There is this blog post from MSDN on how to Add, Remove and Query roles on a Windows 2008 Server

From a PowerShell command prompt

servermanagercmd.exe -query roles.xml

See full blog here http://blogs.msdn.com/b/patricka/archive/2008/03/05/detecting-what-server-roles-are-installed-on-windows-server-2008.aspx

0

The above answers will work for Server 2008R2 (so long as you're running Powershell 5 or better), however if you're intending to pipe this out to Add-WindowsFeature (or generating a DSC script) you probably won't get the desired effect as the above lists will sometimes include sub-features which might not be desirable for your application if some of the sub-features are intentionally disabled.

This version of the above script delivered exactly what I wanted:

Get-WindowsFeature | Where-Object { $_.Installed -eq $true -and $_.SubFeatures.Count -eq 0}
0

I followed this link for exporting installed windows features and import them on a new server.

To just get all the Installed Roles and Features -

Get-WindowsFeature | where{$_.Installed -eq $True} | select displayname,name

Export all roles to a .csv file so that you can then use it on another server -

Get-WindowsFeature | where{$_.Installed -eq $True} | select name | Export-Csv C:\scripts\Roles.csv -NoTypeInformation -Verbose

Now you can use this .csv file to on a new Server with exactly the same roles and features -

Import-Csv C:\scripts\Roles.csv | foreach{Add-WindowsFeature $_.name  }

I have tried this on Windows server 2012, and I think it should work for other versions also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.