Rants, rambles, news and notes from another geek

My Latest Powershell/XML Hack

I have a little text file I keep quotes and silly quips in. I’ve been collecting it for years. I recently installed a little program called Messenger Plus Live that lets you run scripts and do all kinds of other interesting things to Live Messenger.

Long story short, there is a script for Messenger Plus that lets you have a database of quotes that rotate in your tagline in Messenger. I wanted my little text database in there, but it had its own XML file format.

Powershell to the rescue:

$lines = gc 'quotes.txt'
$dom = [xml] (gc 'quotes.xml')
$lines | % { 
$elt = $dom.CreateElement("sentence")
$elt.set_InnerText($_)
$dom.root.AppendChild($elt)
}
$dom.Save('quotes.xml')

God I love this thing! Who needs perl anymore? Not me.