Server Manager cmdlets
The Server Manager cmdlets are there to help the administrator with any action the Server Manager would normally allow them to perform.
Table-17 Server Manager cmdletscmdlet Name | Description |
---|---|
Add-WindowsFeature | This cmdlet is used to install features |
Get-WindowsFeature | This cmdlet is used to get the list of features available. The installed features will show an [X] by them and the ones that are not installed will show [] |
Remove-WindowsFeature | This cmdlet is used to remove an installed feature |
With the PowerShell Server Manager cmdlets, you can add, check, and remove roles, roles services, and features from servers in your environment. Before you can have access to these cmdlets, you have to import the Server Manager module via the import-module cmdlet. Follow these steps to import the Server Manager Module:
- Startup PowerShell
- Type import-module ServerManager
- Once the cmdlet completes, you can check that you have access to the Server Manager cmdlets by typing get-help *windowsfeature*. Remember that the * are the wildcards and this will return all cmdlets with windowsfeature anywhere in them. A list of three cmdlets should then be listed for you as shown, which will include Add-WindowsFeature, Get-WindowsFeature, and Remove-WindowsFeature.
These cmdlets are very straightforward in their use and purpose as can be determined by their names. Add-WindowsFeature is the one the administrator will be using to add the roles, role services, and features; Get-WindowsFeature is the one that will be used to get the information about them, and Remove-WindowsFeature to remove them directly. The syntax is just as straightforward. Assume that you wanted to install the telnet client on your server. Instead of starting up Server Manager and using the wizard, you can do it directly with PowerShell. The first thing you need is the name of the feature you want to install. Sometimes, you will not know the exact name that Server Manager uses and will need to look it up. This is done with the Get-WindowsFeature cmdlet. Typing Get-WindowsFeature at the prompt will return a list with all the potential features with a column showing their display name in Server Manager and a column showing their name. The Display name column will also have an [X] next to any feature already installed. This way if you need to, you can check to see if the feature you want is already installed. The name column is what will be needed for the cmdlet to run properly. In this case, the name of the telnet client is telnet-client. Looking at the Display name column, you will see that it is not installed by default. With this name, you can now call the Add-WindowsFeature cmdlet by typing Add- WindowsFeature telnet-client and then hitting enter. You will then get the prompt back. Now, you try the Get-WindowsFeature cmdlet again. You can type it without an argument like you did the first time, or you can specify that you want to see the telnet client feature specifically by giving it the name and typing Get-WindowsFeature telnet-client. You will now be able to see that the telnet client has an [X] before it, showing that it has been installed.
The Remove-WindowsFeature cmdlet is the cmdlet you will be using to remove modules, as the name implies. Following the previous example, let us say you now want to remove the telnet client. Since you already know the name of the feature you want to remove, you do not need to look it up, but if you do not know the name, you could just look it up with Get-WindowsFeature as described earlier. The next step is to issue the cmdlet by typing Remove-WindowsFeature telnet-client and hit enter. PowerShell will process the cmdlet and then return a summary describing if the removal was successful, if a restart is needed, and a reminder of what feature was removed.
So, the question is, when would you use these features? Imagine you are the lucky administrator tasked with building up a Web server farm consisting of 15 new servers which all require IIS to be installed. Instead of trudging your way through each server one at a time and utilizing the Server Manager GUI to perform the installs, you would instead be able to create and utilize a repeatable PowerShell cmdlet or a sequence of cmdlets. Even if you decided to log on to each server and execute the cmdlets instead of utilizing the GUI, you would save a hefty amount of time in performing the installations. Now, add to this the equation the fact that you can use PowerShell's new remoting features or even just write it once and have it available on the network, and you can see the reason why you would use it.