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…
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.
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)
Here’s what the variable looks like
Now, let’s use it to view the individual results
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.