Thursday, May 7, 2009

Create a server form with PowerShell 2 & Word 2007 (Part 1)

What if it was possible to get pertinent informations about all our Windows servers and generate a detailed report and then send it by mail to our manager monthly ?

We will have more time for cofee ? sure... Or maybe we will have more time to enhances the efficiency of our production processes !

Well, in this post splited into 4 parts, we will do the job !

We need 2 things :
1. PowerShell V2 : of course ! :)
2. OpenXML SDK 1.0 : library used to work with DOCX format (OpenXML).

If you didn't install PowerShell V2, go to this post ! Else, just download OpenXML SDK 1.0 and install it.

You have to know that Cmdlets (powerShell commands) exist to work with OpenXML format. Theses Cmdlets will make easier our job : PowerTools (Open source project developed using C#).

To install PowerTools, you will need to download the source code and then compile it using Visual C# Express (the free edition :)) to build the DLL which contain Cmdlets. Or you can download the DLL from here...

Then, you have to do in a PowerShell session :

PS> cd C:\Windows\Microsoft.NET\Framework64\v2.0.50727
PS> .\InstallUtil.exe C:\OpenXml.PowerTools.dll
PS> Add-PSSnapin OpenXml.PowerTools

Installutil.exe is located in the .Net 2 Framework folder. In the previous example: « C:\Windows\Microsoft.NET\Framework64\v2.0.50727». The POwerTools DLL is located in C: root folder.

Since we have all the prerequires we can do the job : Generate a Word 2007 document !
This work is divided into 3 parts:

1. Selecting and getting pertinent information from our servers,
2. Creating a Word 2007 template for the report,
3. Report creation.

Each step will be detailed in a post to preserve the suspense... ok sorry... :)

See you soon for the first step !
Until then, check that you installed all the prerequires !

No comments:

Post a Comment