The Lost Documentation: Add-WindowsFeature

I was recently working on a PowerShell script to install a Windows feature and while reviewing the documentation for the cmdlet I found something missing…

http://technet.microsoft.com/en-us/library/ee662309.aspx

image

The documentation shows the return type as being an object of type Microsoft.Windows.ServerManager.Commands.FeatureOperationResult, but I couldn’t find any information about that class.  In the MSDN documentation that class would typically be a hyperlink to another page that explains the properties and methods for that object as well as links to any related objects.  Call me spoiled, but I find it much easier to code against an object when I know what it looks like.

Given that I couldn’t find the information anywhere online, I figured I would document it within my own blog, in the hope that I can save some time for somebody else.  The following information was gathered using the Get-Member cmdlet against the root object and it’s child objects.

image

image

image

image

So, now that we understand the objects involved, how do we make use of it?  Well, here’s an example:

First, let’s install a couple of features and assign the result to a variable (I’ve chosen to install multiple features to demonstrate looping through the FeatureResult array)

image

Here’s what the variable looks like

image

Now, let’s use it to view the individual results

image

From here you can do all kinds of things like check to see if the install was successful or if the install requires a restart, both are boolean values that can be easily checked with an IF statement.

Note: This works in Windows Server 2012, but the cmdlets have changed from Add-WindowsFeature and Remove-WindowsFeature to Install-WindowsFeature and Uninstall-WindowsFeature.

Leave a Reply

Your email address will not be published. Required fields are marked *