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.

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-DCV, 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, 2017, 2018 and 2019 Robert received the VMware vExpert award for his contribution to the community of VMware users over the past year. In 2017 Robert also received the VMware vExpert Cloud award. PernixData made him in 2015 a member of the PernixPro.

5 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

  3. PD Subraa says:

    “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.

  4. M.H. van der Hoek says:

    I guess you already know about this one, but for thos who don’t…In my opinion the “Crayon Syntax Highlighter” plugin is the way to put any kind of scripts (including powershell) to a wordpress website.

Leave a reply to PD Subraa Cancel reply