Anybody that knows me knows I love to find ways of leveraging Windows PowerShell to produce a solution.   It’s something that’s just sitting on a Server waiting to get used.

My boss pointed me to a really cool script to generate documentation for Configuration Manager 2012 R2 but it had a catch.  “It needs Microsoft Word and Configuration Manager 2012 R2 Management Console on the same machine.”

While this is NOT a major pre-requisite I prefer to have the option of “If I need to run this on an environment, I want to have as FEW pre-requisites as possible, including Word.”

Although Microsoft Word is an AMAZING Word processor which can be automated with PowerShell it sometimes is a bit of overkill for some simple documentation.

Because truth be told, I can have Windows PowerShell generate RTF documents without Word since they are just an ASCII text file, a fairly complex one but just an ASCII text file.

This is nothing new.  I’ve blogged about it before and even uploaded some simple scripts to Technet to demonstrate this idea. Here is a simple script that produces a very Basic RTF file producing this output

Hello World

How’s it Going?

$Header=”{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}{\f1\fnil\fcharset2 Symbol;}}`r`n{\*\generator Riched20 6.3.9600}\viewkind4\uc1 “
$Footer=”}”

$Line1=’Hello World\par’

$Line2=’How’s it Going?\par’

Add-Content –path somefile.rtf –force –value $Header

Add-Content –path somefile.rtf –force –value $Line1

Add-Content –path somefile.rtf –force –value $Line2

Add-Content –path somefile.rtf –force –value $Footer

 

Save this script as MAKERTF.PS1 , execute it and you’ll have a very simple RTF file.

Ok that was pretty cool right?  What else can we do other than lines of output?   Well THAT’S the neat part! 

The capability to generate simple tables, bulleted points, Headers and even Bullet points are all features of the RTF format.   

Next time we’ll wrap this simple script into some more useful functions which we can add to our other scripts to give them a document generation feature.

Advertisements