- Install Ansible on Windows - Thu, Jul 20 2023
- Use Azure Bastion as a jump host for RDP and SSH - Tue, Apr 18 2023
- Azure Virtual Desktop: Getting started - Fri, Apr 14 2023
This is the sixth part of the Windows PowerShell series. PowerShell beginners should also read the previous parts.
In Windows Server 2008 a server role represents an installable unit of functionality that defines the primary function of a server. For instance, you may install Active Directory Domain Services (AD DS) to create a dedicated domain controller for your forest.
By contrast, Windows Server 2008 features are a bit more slippery to define. Like a server role, a feature is an installable unit of functionality. However, whereas a server role typically defines the chief duty of a server, a feature (at least according to Microsoft marketing literature) “provides auxiliary or supporting functions” within a system. Thus, a single server may be the holder of several features.
As you probably already know, you can manage server roles and features by using any of the following tools:
- ServerManagerCmd.exe
- Server Manager console
- Windows PowerShell
You also may know that, as of Windows Server 2008 R2, the ServerManagerCmd.exe command-line tool is formally deprecated (read: does not work anymore); you are instead politely “encouraged” to use Windows PowerShell instead. In this article we will learn how to leverage the Windows PowerShell scripting and automation environment to install, administer, and remove server roles and features.
Installing Windows PowerShell 2.0
The first order of business is ensuring that your target Windows Server 2008 computers have Windows PowerShell 2.0 installed. If you are running Windows Server 2008 RTM, then you can use the ServerManagerCmd.exe utility to install Windows PowerShell:
OS>ServerManagerCmd –install PowerShell
If you run Windows Server 2008 R2, then you already have Windows PowerShell 2.0 installed. To verify your installed Windows PowerShell version, open an elevated command prompt, issue the command powershell to start a Windows PowerShell session, and then invoke the $Host.Version method. All of these commands are depicted in the following exhibit:
Verifying Windows PowerShell
NOTE: There is a world of difference between Windows PowerShell v1.0 and v2.0. Please ensure that you are running PowerShell v2.0, and be certain to run Windows Update to download the latest enhancements to the technology.
Installing a Role or Feature
As far as I am personally concerned, it is a blessing that Windows PowerShell does not try to split hairs and differentiate server roles and features. As you will see momentarily, all roles and features appear in a single master list.
From an administrative command prompt, fire up Windows PowerShell and issue the cmdlet Import-Module Servermanager to load the Server Manager PowerShell module.
Next, run the cmdlet Get-WindowsFeature to see a tree list of all available server roles and features. Any roles or features that are currently installed will appear with an X within the selection brackets. Pay particular attention to the role and feature short names in the Name column, as shown in the below screenshot; we will need those IDs to perform the next step.
Listing available server roles and features
NOTE: In Windows PowerShell nomenclature, a module is a self-contained, reusable library of related PowerShell functionality. Most Microsoft server technologies, such as SQL Server 2008, SharePoint Server 2010, and Exchange Server 2010, ship with their own custom modules to enable administrators to use PowerShell with those products.
We use the Add-WindowsFeature cmdlet to install both server roles and features. To leverage this cmdlet, we simply pass a comma-separated list of either display names (in quotes) or short names for the roles and/or features you wish to install.
PS>Add-WindowsFeature role, feature, etc.
See the following exhibit for an interface example in which we install the File Server, Domain Name System (DNS), and Dynamic Host Configuration Protocol (DHCP) server roles on a Windows Server 2008 R2 server.
Installing roles and features
To verify that the new server roles have been installed successfully, let’s fire up Server Manager and have a look at the Roles tree:
Verifying server role installation
Ah, success!
Removing a Role or Feature
Removing Windows Server 2008 roles and features by using PowerShell is an equally simple procedure. To do this, we invoke the Remove-WindowsFeature cmdlet. You can throw in the optional –restart parameter to specify an automatic server restart if Windows needs to do so.
Removing server roles
One word of warning: If you do elect to add the –restart parameter to your cmdlet, the server will restart (if necessary) with absolutely no timeout or other warning. It just goes!
Conclusion
At this point you should be able to manage Windows Server 2008 roles and features by using PowerShell. I will leave you with some related study resources if you are so inclined. I hope that you found this article helpful. Thanks!
For Further Study:
- Adding Server Roles and Features
- Checking Server Roles with PowerShell
- Windows Server 2008 Server Management
- Windows PowerShell
Thanks for your PowerShell Tutorial for admins series! Good job! A nice way to get started with PowerShell.
i appreciate people which take the time to share their knowledge with others!