The Blown Light Bulb

Information worth to share...


How to install and remove roles, roles services and features on Windows Server 2008 from command-line

Microsoft Windows Server 2008 offers you several tools to install or remove roles, roles services and features from your server. I want to expose the use of two of them; the oldest one Server Manager command-line and the Windows PowerShell cmdlets for Server Manager that is available on the most recent edition of Microsoft’s server operative system.

First of all you need to know that Microsoft has deprecated the first one on Windows Server 2008 R2 edition because Windows PowerShell cmdlets for Server Manager offer some significant advantages:

  • Windows PowerShell cmdlets can be run on a computer that is running the Server Core installation option of Windows Server 2008 R2.
  • Windows PowerShell tools and cmdlets are available for performing some management tasks after a role, role service, or feature is installed.

ServerManagerCmd.exe command

The Server Manager command-line installation accepts parameters to install or remove one or more roles, role services, and features that are separated by spaces. When you want to install or remove more than one role, role service, or feature on a server by using a single command instance, you can also use an XML answer file, especially if you want to configure multiple servers identically.

On Windows Server 2008 you must be a member of the Administrators group on the server on which you want to install or remove software; while on the R2 edition due the UAC you also must run ServerManagerCmd.exe in a Command Prompt window opened with elevated permissions.

Syntax:

  • ServerManagerCmd.exe -query [<query.xml>] [-logPath <log.txt>]
  • ServerManagerCmd.exe -inputPath <answer.xml> [-resultPath <result.xml> [-restart] | -whatIf] [-logPath <log.txt>]
  • ServerManagerCmd.exe -install [-setting =]* [-allSubFeatures] [-resultPath <result.xml> [-restart] | -whatIf] [-logPath <log.txt>]
  • ServerManagerCmd.exe -remove [-resultPath <result.xml> [-restart] | -whatIf] [-logPath <log.txt>
  • ServerManagerCmd.exe [-help | –?]
  • ServerManagerCmd.exe –version

Check Microsoft’s TechNet Overview of Server Manager Commands for a complete parameter’s description list.

Windows PowerShell cmdlets for Server Manager

Windows PowerShell cmdlets for Server Manager accept parameters to install or remove one or more roles, role services, and features that are separated by commas.

Notice, that they can only be used on Windows Server 2008 R2 edition, they are not available for previous versions.

To run any Server Manager-related Windows PowerShell cmdlets, you must be running Windows PowerShell with elevated user rights.

You must also load the Server Manager module into each new Windows PowerShell session before working with Server Manager cmdlets.

Syntax:

  • Add-WindowsFeature [-Name] <string[]> [-IncludeAllSubFeature] [-logPath <string>] [-WhatIf] [-Restart] [-Concurrent] [<CommonParameters>]
  • Get-WindowsFeature [[-Name] <string[]>] [-logPath <string>] [<CommonParameters>]
  • Remove-WindowsFeature [-Name] <string[]> [-logPath <string>] [-WhatIf] [-Restart] [-Concurrent] [<CommonParameters>]

Check Microsoft’s TechNet Overview of Server Manager Commands for a complete parameter’s description list.

Examples

Let’s make an example with both tools on how to install Print Services [Print-Services] role:

  1. Check if role, role services or feature are already installed or not. 

    servermanagercmd –query 

  2. Install role and all sub features (including Print Server [Print-Server], LPD Service [Print-LPD-Service], _Internet Printing [Print-Internet] and needed features) 

    servermanagercmd -install Print-Services -allSubFeatures

  3. Remove Internet Printing [Print-Internet] role service and sub features. 

    servermanagercmd -install Print-Services –Restart

The same but with PowerShell…

  1. Check if role, role services or feature are already installed or not. 

    Import-Module ServerManager
    Get-WindowsFeature Print-Services

  2. Install role and all sub features (Remember to run the Power Shell command as Administrator). 

    Add-WindowsFeature Print-Services -IncludeAllSubFeature _–Restart
    _

  3. Remove Internet Printing [Print-Internet] role service and sub features. 

    Remove-WindowsFeature Print-Services –Restart

To extend this information you can check Microsoft’s TechNet Overview of Server Manager Commands.