How to add a PowerShell script to your WordPress.com blogpost
July 16, 2011 4 Comments
After starting this blog two weeks ago, I wrote a post that contains a PowerShell script. But I still have not published this post, because I could not find a good way to include the PowerShell script in my post.
I saw that a lot of other blogs use the SyntaxHighligter plugin by Alex Gorbatchev. But I thought that you needed to have a WordPress.org blog to be able to upload plugins. And this is a WordPress.com blog where uploading plugins is not possible.
Arne Fokkema gave me the link to his article How to post PoSH code with Live Writer. It contains a video that shows how to use PowerGUI to save a PowerShell script as HTML and how to use Windows Live Writer to write the blogpost and include the HTML code of the PowerShell script. This is the same technique that I use to post scripts at the VMware Communities. I have tried this and the blogpost looks good in Windows Live Writer. But when I upload it as a concept to WordPress, it removes the line breaks and the whole script is displayed on one line.
I first thought that this might have to do with the WordPress thema I used. So I changed the theme of my blog to the same Enterprise theme that Arne uses for his blog. But this didn’t solve the problem. So I was stuck.
Luckily yesterday I found a support blogpost by WordPress that solved my problem: Code » Posting Source Code. It shows how you can use tags to wrap around a script to display it in a blogpost. And it uses the SyntaxHighligter software under the hood to implement this. Besides PowerShell there are a lot of other languages supported. Like: javascript, python and perl. Of cource I tried this and it works good.
So my problem is solved. You can expect my blogposts containing scripts soon.
Robert,
Why not post the code to gist.github.com or poshcode.org. Both of those will let you post a single text file easily and do syntax highlighting. They also both give you a one line tag that when inserted into a blog post puts said syntax highlighted code in the blog post. I’ve used both on my blog, as well as a syntax highlighter plugin for wordpress. I use the syntax highlighter for small snippets.
Here is an example of me using poshcode.org on my blog: http://www.justaprogrammer.net/2011/03/26/how-many-ways-can-we-script-a-stored-proc-or-udf/
Here is an example of me using gist: http://www.justaprogrammer.net/2011/06/25/moving-your-spring-roo-hibernate-project-from-hypersonic-to-postgresql/
Thanks for the tips.I must say that I am happy with my current solution. Although it has a flaw that it sometimes removes the comment-based help from a script. I was already thinking about posting my scripts as well on poshcode.org. Maybe I switch to your solution then. 😉
Pingback: Powershell Mini-Series: Search-Content « Secret SQL
“line breaks and the whole script” – will surely be removed when going with your option. Should you be happy with what you have , its fine.
I rather recommend github for these activities.