How to add a PowerShell script to your 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 blog to be able to upload plugins. And this is a 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.

4 Responses to How to add a PowerShell script to your blogpost

  1. Robert,

    Why not post the code to or 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 on my blog:
    Here is an example of me using gist:

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

Leave a Reply

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

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

Facebook photo

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

Connecting to %s

%d bloggers like this: