PowerShell – Programmtically post and retrieve PowerShell code on your blog

by Doug Finke on December 30, 2008

in PowerShell

James Brundage, from the PowerShell team, has several posts up since the release of CTP3.

One is Write-CommandBlogPost another is The CodeDownloader Module.

I modified his Write-CommandBlogPost. Now I can post PoSh code and it can be pulled off my blog programmatically.

Additionally, I created a Microsoft Live Writer Plug-In, embedding  the PowerShell Scripting engine so with a few clicks I can inline my PoSh code in my WordPress blog post.

image

 

Sample PoSh Code

Write-Hello.ps1

Synopsis:

Writes Hello to the console

Syntax:

C:\PoSHScripts\Write-Hello.ps1 [[-who] [<Object>]] [<CommonParameters>]

Detailed Description:

Sample script writes Hello to the console

Examples:

--------------------- EXAMPLE 1 ---------------------

Write-Hello "World"

Command Parameters:

Name Description
who Who to say hello to

Here’s Write-Hello.ps1:

<#
.Synopsis
  Writes Hello to the console
.Description
  Sample script writes Hello to the console
.Parameter Who
  Who to say hello to
.Example
  Write-Hello "World"
#>

param($who)
"Hello $who"

Automatically generated with a custom version of Write-CommandBlogPost

Things you need

Download Live Writer C# Project.

You can download the Live Writer SDK and build the DLL, below is the Help About showing the version of Live Writer I am using.

Or copy the BlogPoSh.dll and Write-CommandBlogPost.ps1 from the bin/debug to C:\Program Files\Windows Live Writer\Plugins.

These steps are setup in the VS IDE for the project.

image

Upcoming Post

I will post the script that is ‘added’ to James’ Code Downloader which enables programmatic extraction the code above.

In James’ examples, he provides plug-in scripts that can programmatically download scripts from Microsoft PowerShell Blog posts and PoshCode.org.