Introduction to PoshWSUS, a Free PowerShell Module to Manage WSUS
Summary: Guest blogger, Boe Prox, discusses the development of the free Windows PowerShell module that he wrote to manage WSUS.
Microsoft Scripting Guy, Ed Wilson, is here. Today we are celebrating our 2000th Hey, Scripting Guy! blog. I think that in the spirit of community, it is appropriate that today we also have a guest blogger, Boe Prox, who is talking about a project that he developed and shared on CodePlex.
I will let him speak for himself—take it away Boe…
After a week of working with Windows PowerShell and WSUS and showing you some pretty cool things that you can do with the two, I am going to talk about a project that I have been working on that will make administering a WSUS server easier with Windows PowerShell.
Here are the blogs from the past week if you would like to catch up:
My plan today is to give an overview of what PoshWSUS is and why I built it the way I did, plus show a couple of small examples. Tomorrow I will show you more examples of using PoshWSUS to accomplish some of the same tasks that I have been showing earlier in the week in addition to a few new things.
What is PoshWSUS?
PoshWSUS is a module that I designed and built to help a system administrator manage a WSUS server easily by using Windows PowerShell. To download the module, see PoshWSUS in CodePlex.
Currently, there are 60 commands that are available in version 2.0, which was recently released on Dec. 18, 2011. There are various commands that one can use with this module. Although a majority of commands are query-type commands, there are other commands that allow you to approve or decline updates, create groups, add clients to groups, and work with synchronizations (to name a few). Here is a full list of the commands available:
PoshWSUS originally started as one module file (.psm1) that contained approximately 45 commands. This file was over 2000 lines long, which made it extremely difficult to work with, especially when it came time to troubleshoot one of the commands.
When it came time to work on version 2.0 of PoshWSUS, I made the decision to separate each of the commands into its own file to make it much easier to work with. I can then use the module file to go through each of the files and dot source the functions from those files.
I work with WSUS almost daily, and wanted a way to quickly perform a query or quick update approval against WSUS without having to jump onto the Administration Console and click, click, click my way to victory. Another piece of motivation that I used in writing this module is that there was no module for WSUS at all. Sure, there are various scripts available that perform various queries, approvals, and so on—but never a module that really tied everything together and covered a wide threshold of things to do in WSUS. Thus, PoshWSUS comes into play to fill in that gap and allow people to manage their WSUS server from the command line.
So with that, I will talk a little about some of the new things that my latest version brings into play.
Working with custom types
One of the things that I was determined to change was the way that the output from any command would be displayed in the console. By default, if you run a command that would list a client or update, you would be crushed by a sea of data for each client and update that was returned unless you used Select-Object or Format-Table and listed only the properties that you wanted to see. Obviously, I couldn’t add this into my commands because I would lose the object type and also limit the amount of data that was available to a user.
Here is an example of such output from an update query:
Pretty wild, isn’t it? Well, thanks to custom-type formatting, I can dictate what is displayed by each output while still preserving the object type. Now, I won’t go into detail about how this works because that would be a blog (or two) in itself. But as you can see in the following example, it greatly simplifies the display of the output while still retaining the object’s type.
So it looks better AND retains the object type.
Even if you use Format-List, it will not show every property unless you specify by using the “*”. This is shown here.
Adding properties to an existing type
While most of the data that is returned by a query is useful, sometimes you get some properties that aren’t as helpful in their current state. For instance, let’s look at the following output:
The Updated is not exactly something that we can use because we have no idea what update it is referring to. By adding some extra properties for this type (Microsoft.UpdateServices.Internal.BaseApi.UpdateSummary), we can translate that ID into the following:
As you can tell, there are a couple of properties that are null, and this is by design for this object. How this query is performed will determine which of the UpdateTitle, ComputerGroup, and Computer properties would be populated. This technique is used with several types to provide clearer data that is returned on various queries.
Most of the information about working with type formatting was via Jeffery Hicks and my time at the PowerShell Deep Dive where he presented on the subject. Here is some information about Jeff:
Blog: The Lonely Administrator
YouTube video of Deep Dive session: Mastering Format and Type Extensions
Removing plural nouns
Another thing that I changed was some of the names of the commands in the module. Originally, I had several modules that were named with a plural noun and another that was singular, such as Get-WSUSClient and Get-WSUSClients. It is poor practice in Windows PowerShell to have a plural-named noun for a command, so I made sure to merge those commands into one that used a singular noun.
Feedback from the community drives any project, and this module is no different. I encourage anyone who uses this module to please let me know what they like and don’t like about it. Any bugs that you find or anything that you feel would make a good feature is always helpful to the growth of PoshWSUS. You can log issues and ideas in the CodePlex Issue Tracker.
That pretty much sums up my module, PoshWSUS and gives you a little more information about its beginnings and some of the new things I did with version 2.0. Tomorrow I will go into how to use PoshWSUS, explore some of the commands, show you how to achieve some of the same results from some of the commands we have been using during the past week, and show you a few new things. See you tomorrow!
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at firstname.lastname@example.org, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy