Not sure whose code this was, there was no information at the top of this. This is not my code, I just made some changes to it to use the new ScriptDotNet2.
http://pastebin.com/CRQrU09F----------------------------------
Updated: 3/22/2015
*Changes and Fixes to work with ScriptDotNet2