How to add a PowerShell script to your WordPress.com blogpost

WordPress logoAfter 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.

Advertisements

About Robert van den Nieuwendijk
Robert van den Nieuwendijk is a freelance senior systems engineer with over 30 years of experience in the IT industry. He focusses on VMware vCloud Suite and Microsoft Windows Server. He tries to automate as much of his work as possible using Microsoft PowerShell. Robert is the author of the books “Learning PowerCLI” and “Learning PowerCLI – Second Edition.” Robert is a frequent contributor and moderator at the VMware VMTN Communities. He has a bachelor degree in software engineering and holds the following IT certifications and accreditations: VSP 2016, VTSP 2016, VCP4-DCV, VCP5-DCV, VCP6-Cloud, VCP6-CMA, VCA-Cloud, VCA-WM, VCA-NV, VMSP, VMTSP, ZCS, ZCP, ZCP-Cloud, MCSE, MCSA, MCP, MCP+I, PRINCE2 Foundation and ITIL Foundation. In 2012, 2013, 2014, 2015, 2016 and 2017 Robert received the VMware vExpert award for his contribution to the community of VMware users over the past year. PernixData made him in 2015 a member of the PernixPro.

3 Responses to How to add a PowerShell script to your WordPress.com blogpost

  1. 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. 😉

  2. Pingback: Powershell Mini-Series: Search-Content « Secret SQL

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: