The Practice event started on the first of january and the scenario was offered to us through a zip file that contained two files :

  • A pdf wit the winter scripting games 2014 players guide
  • The event itself.

The scenario has been written by MVP Richard Sidaway and was entitled  : “Server  Inventory”.

I am not going to copy/paste the scenario here, but basically, it asked us to scan a specefic set of ip’s, verify if the IP’s are used, if not, write does available IP’s down in a file, and for the ones available, gater the computername of them.

With that return, we needed to do a specefic computer inventory :OS version, SP pack installed, last software update installed, what type of application  is running on the server (SQL, Sharepoint, Exchange etc..).

The results returned should be (when possible) transformed into a graph, and then exported to an HTML file.

An optional step is to export the graphs directly into a powershell presentation.

I) Dividing the work:

So, in my opinion, this was probably the most “complicated” thing or lets say the “newest thing” that we had to do here : Diving the work “equally” between the 6 different members of the team. The event was eventually a bit “light” for 6 members, but we stilled managed to divide consequently and I tried to cut it in a way that each one of us could have something interesting to script.

We have identified 3 main sections in this scenario :

  • The IP Scan
  • The Server Inventory
  • The exports

Each section has been attributed to two team members and we organized a new date & time to do another google hangeout.

Since we where from 4 different timezones, it was not easy to find a time where everybody could be present, but  eventually we managed to find one 🙂

Google hangeout became our “Hangeout” (Google found the perfect name for that tool there  ;)) and we had a few meetings on there with the whole team.

The first one to share the work. We decided the functions that will need to be written. What type of output they need to give, and what the next function needs as input. (This was done before the meeting, and basically everybody agreed with the division that has been made).

We shared some scripts written on different projects, and some links concerning different subjets that one or another had in their favorites in order to avoid us to lose to much time searching the internet for “the” blog that will bring us the solution.

II) The technical aspects:

Will talk shortly about the two first parts  ( Ip scan and Gather information) since I have mainly worked on the export part (HTML and PowerPoint).

But, of course I am pretty curious and I looked into the code that has been written by my fellow mates, and I must say, that reading code, is most probably te best way to learn new methods.

1 ) Ip scan:

The ip scan has been handled by Dexter and Allister. I think they have done a very good job, and their functions are really fast !

 

What was pretty cool here I think, they used very strong parameter validation in order to be sure to validate that the inputs are IP adresses.

as for instance this section that covers the parameter validation from the IP address range input:

They used a lot of access to dotnet class, such as this call to system.net.dns to resolve the machines hostname.

 

2) Gater server information:

What was asked here, was to retrieve a lot of information from the different servers / IP’s that would have been identified in section 1. This is pretty much a routine task if you have participated to the scripting games before 😉

Of course, this information can be retrieved very easily with WMI. François-Wavier (The lazy Win admin) and Guido wrote that part of the script and did great good job! They gave for example the possibilty to choose an alternante protocol :

They also did some very strong parameter validation and offered directly the possiblity to run the script with alternante credentials by integrating the following code:

 

also every set of data was possible to get retrieved individually from each other by calling each parameter with “switch”

 

 

Now lets look into the export part.

3) Exporting the data:

a)The graphics

We basically divided the export part into two sub parts : Generating the graphic, and exporting the data + the graphic.

Benjamin did a great job on generating beautifull exports like the one below with the function he build :

 

Chart generation example

Chart export example

 

I have been focusing on the export parts. The HTML part was pretty simple, especially since we used the “-fragment” parameter of the “ConvertTo-HTML.

Actually, it became very easy once I read this super article from the  “powerShell Deep Dives” book. There was an article about html export and it seemed to be tailored for us! (I must say, that in general, this book is really good !)

The article has been written by “Jonathan Medd” , he is part of one of the Scripting games “coaches” and you can visit his blog here.

The article basically indicated how to use the -fragment parameter of the “ExportTo-Html” cmdlet and how to add an image into the export ; Perfect ! That’s exactly what we needed !

Benny has a lot of experience in generating these kind of reports, and came with the idea to use a function that would actually transform the graph into “bytes” version, and intégrated directly in te script. This means that the image file of te chart actually never needs to be saved on the file system. That’s great !

This is what we came up with.
At the end, the HTML export section looked like this:

($ExportPath would of course contain the date and time of when the file was generated  followed by the .html extension).

And this is what the HTML export looked like after Benny re-aranged the CSS with his crazy “gandalfy” CSS little fingers 😉

 

HTML export - POSH Monks - Winter Scripting Games 2014

And the data section here :

POSH Monks - Winter Scripting games 2014 -  Practice Event

 

It looks good doesn’t it ? 😉

 

b) The other exports sections: CSV and Powerpoint.

 

The scenario asked for HTML, CSV, and PowerPoint exports. HTML we got it covered up here, and CSV, was actually the first one I wrote since it was so simple to that with the integrated cmdlet in powershell

But exporting to PowerPoint ?!! I have written in the past a script that would generate automatically the documentation for a script by reading its comment based help section and exporting it to a predefined word template.(Maybe I should think of blogging about that scriptone day…) I used com objects for that.

So, I knew I was looking for Powerpoint exports with COM objects.

And here, i stumbled in a few problems:

  • The first one was concerning the fact that I couldn’t find anything like asked in the scenario that could fullfill our needs.
  • The second one, is that either the documentation of the COM objects are not so well written (FYI: English is also not my mother language), or COM objects is simply just not that easy to understand.

I would say both !!

Anyways, I managed to swim through this event, and learned a LOT on that topic. I will not post any code concerning the PowerPoint export part since I am planning to blog about it soon.

Ineed, the lack of infos available on the internet (or at least my searching results where not concluding at all!) gave me the idea to write something that could explain a bit how theses COM objects work.

In the mean time, find here what our powerpoint export looked like 😉

ppt

 

It is pretty basic I agree. (I am not really an artist as you can see ;)) But this is generated automatically, and ready to be used for a presentation 🙂

 

III) The biggest learning point : Putting everyting together.

Dividing a script in 6 parts, let them all be written by 6 different (amazing !) scripters, and then put everything together in one and unique script is something, that none of us had done before.

I have worked on projects where several scripters would each of them write a script that would do certain actions to a system (in my case SCCM, Active Directory, CSV files). But our scripts were dependant on the results that the scripts would have on the system.(EG: Computer object in OU, Collection present in SCCM etc..) But not on each other function or script.

Here, it was a hole new experience since we wanted to have 1 script, that could be called very easil, with only a few arguments. I personally think that it would not have been that of a problem if this task was done alone. But here we had to face different scripters, different time zones (4!!) different scripting styles.

We tried to organise, before even starting scripting, the functions that needed to be written, and what kind of export they needed to have as input & output. But, even with that, it wasn’t so easy.

So putting the wole script together didn’t worked out as expect. We deceided to upload the three different sections as seperate scripts.  After all, the scenario mentionned the fact that everything should be set all into the same script 😉

Anyways, I really think that working as a team for the winter scripting games is a great idea in condition that there is enough work to share between 6 team members of course ! 😉

Well, that’s it for this review. Now, it is time to Attack the second (the first ?) event  : “Pairs” written by “the” PowerShell legend himself : “Ed Wilson” 🙂

Have fun ! Proost !