I haven't done a serious learning project for a while so this week I decided to play around with Windows Server 2008 and PowerShell. I'll post some thoughts about Server 2008 soon (at first glance it looks terrific once you get past the fact that IIS is now a "role" instead of something you install). But I wanted to post a PowerShell example first because I wanted to do something with it that I couldn't find information about anywhere -- specifically, perform a database query and dump the contents to the console. (Later we'll get fancy and dump it to HTML or send it somewhere via email, etc.)
PowerShell can invoke any .NET object, so I knew it was possible to do database stuff with a PowerShell script, but I couldn't find any examples anywhere, so here's what I cooked up via trial and error.
The first step is to create a database connection:
[system.reflection.assembly]::LoadWithPartialName("MySql.Data")
$cn …