patrimonio designs - Fotolia

Manage Learn to apply best practices and optimize your operations.

Manage multiple servers with PowerShell Server Manager

PowerShell Server Manager allows administrators to manage multiple servers, Windows roles and features -- all from a single console.

Administrators for large Microsoft environments that use Windows Server 2008 or higher likely have had to manage...

Windows roles. Windows Server has roles and features that allow admins to add, remove or modify features by clicking a checkbox. However, clicking checkboxes isn't the most automatic way to manage servers. This is where Windows PowerShell comes into play.

Windows Server Manager is a graphical user interface (GUI) that creates a single area for managing server identities and system information. The interface allows admins to point and click on various tasks. While this works for environments that have a few one-off servers, it doesn't work for environments with mass deployment of servers. Shifting to the command line can simplify things.

PowerShell has a module called ServerManager that contains useful cmdlets to help the administrator manage roles and features (Figure 1).

PowerShell Server Manager module
PowerShell Server Manager module

In this example, there are two aliases and five actual cmdlets and functions. To be more concise, we will use the cmdlet/function names here. To start, determine all the roles and features available on a given system. To do so, use Get-WindowsFeature.

When you use the Get-WindowsFeature without parameters, it returns all roles and features on a system -- whether or not they are installed. Figure 2 shows a handful of the features available on the test system.

Get-WindowsFeature options
An example of some the Get-WindowsFeature options

To get only the features that are currently installed, use the Where-Object cmdlet (Figure 3).

Where-Object cmdlet
The Where-Object cmdlet calls up installed features

What do you do when installing a new Windows feature? You can use the Install-WindowsFeature. For example, if I want to install the SNMP service on my local machine, I’d use the Install-WindowsFeature cmdlet with the Name parameter. The feature has been successfully installed (Figure 5).

SNMP service
The SNMP service is installed

When removing features, use the Remove-WindowsFeature cmdlet. You can remove features just as easily as you can install them using the same parameter name of Name (Figure 6).

Remove-WindowsFeature cmdlet
Remove Windows features using the Remove-WindowsFeature cmdlet

The UI notes that you must restart the server to finish removing a feature. If you’re using this in a script, you might not want to do that manually. The Install-WindowsFeature and Remove-WindowsFeature have Remove parameters that you can use in case the server automatically restarts (if it needs to) after running each cmdlet.

This is fine if you have a single server, but manually keying this in for several servers would be similar to doing it through Server Manager. Using PowerShell's remoting feature, admins can use the ComputerName parameter to point the task at any remote computer (Figure 7).

ComputerName parameter
Use the ComputerName parameter to point to the task at any remote computer.

What if you want to install a Windows feature on 100 servers? This isn't a problem if you have them in a text file. If you have a CSV file with a header of ServerName -- and all the names of the servers under that -- you can read this CSV file with PowerShell’s Import-Csv cmdlet and start any Windows feature cmdlet.

Import-Csv C:\Servers.csv | foreach { Install-WindowsFeature -Name 'SNMP-Service' -ComputerName $_.ServerName }

This command would read every server name from the CSV and install the SNMP service on each computer at once.

Next Steps

Key components of Windows PowerShell

How much do you know about the PowerShell command line?

Implement SNMP monitoring to augment network monitoring tools

Dig Deeper on Windows administration tools