fix for ‘Cannot convert value “System.Xml.XmlElement” to type “System.Xml.XmlDocument”‘

Quick fix


Param( [xml]$WordpressPostAsXml


Param( [system.xml.xmlelement]$WordpressPostAsXml

Slightly More Detail

I’m in the process of coding a Powershell module to convert an xml file containing the content of my old WordPress site to a set of Markdown files for Hugo.

I got the error:

get-wpHugoFileName : Cannot process argument transformation on parameter 'WordpressPostAsXml'. Cannot convert value "System.Xml.XmlElement" to 
type "System.Xml.XmlDocument". Error: "The specified node cannot be inserted as the valid child of this node, because the specified node is the 
wrong type."
At C:\users\matt\Documents\WindowsPowershell\functions\function-get-WordpressContent.ps1:43 char:63
+ ... goFileName = get-wpHugoFileName -WordPressPost $WordPressPost -Conten ...
+                                                    ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [get-wpHugoFileName], ParameterBindingArgumentTransformationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,get-wpHugoFileName

In summary, there are three relevant functions

  • convert-wpPostToHugo – receieves an exported WordPress site in Xml format. Calls get-wpMatchingWordpressPosts to extract the specified bits, then get-wpHugoFileName for each post
  • get-wpMatchingWordpressPosts – extracts the xml nodes for posts which match a specified string
  • get-wpHugoFileName – called for each xml ‘node’. Returns a file name for the markdown content


function  convert-wpPostToHugo{ 

  Param( [xml][Alias ("xml")]$WordpressXML = "$wp_xml",
         [string][Alias ("string")]$PostString = "ramone" ,
         [string][Alias ("f")]$ContentFolder = "c:\temp"
  write-debug "$(get-date -format 'hh:mm:ss.ffff') Function beg: $([string]$MyInvocation.Line) "

  $MatchingWordPressPosts = get-wpMatchingWordpressPosts -WordPressXml $WordPressXML -PostString $Poststring

  foreach ($WordPressPost in $MatchingWordPressPosts)
    [String]$HugoFileName = get-wpHugoFileName -WordPressPost $WordPressPost -ContentFolder $contentFolder
    write-verbose "`$HugoFileName: $HugoFileName"


function get-wpMatchingWordpressPosts { 
  Param( [xml][Alias ("xml")]$WordpressXML = "$wp_xml",
         [string][Alias ("string")]$PostString = "ramone"         ) 

  write-debug "$(get-date -format 'hh:mm:ss.ffff') Function beg: $([string]$MyInvocation.Line) "

  $Nodes = select-xml -xml $WordpressXML -xpath "//channel/item" | select -expandproperty node | where-object title -like "*$PostString*"

  return $nodes


function get-wpHugoFileName { 

  Param( [xml][Alias ("x")]$WordpressPostAsXml,
         [string][Alias ("f")]$ContentFolder = "c:\temp" )

  write-debug "$(get-date -format 'hh:mm:ss.ffff') Function beg: $([string]$MyInvocation.Line) "

The fix was to change the definition of the $WordPressPost from xml to [system.xml.xmlelement]:

function get-wpHugoFileName { 

  Param( [system.xml.xmlelement][Alias ("x")]$WordpressPostAsXml,
         [string][Alias ("f")]$ContentFolder = "c:\temp" )

  write-debug "$(get-date -format 'hh:mm:ss.ffff') Function beg: $([string]$MyInvocation.Line) "

This makes sense….the variable returned from get-wpMatchingWordpressPosts is no longer a valid XML document – it is just elements of an XML document.

how to install powershell active directory module

install: en_windows_7_professional_with_sp1_vl_build_x64_dvd_u_677791.iso

dism /online /enable-feature /featurename:RemoteServerAdministrationTools-Roles-AD
dism /online /enable-feature /featurename:RemoteServerAdministrationTools-Roles-AD-Powershell

using powershell’s help system to stash your tips and tricks in ‘about_’ topics

There are a bunch of bits of syntax which I struggle to remember.

I’m not always online when I’m using my laptop, but I always have a Powershell window open.

This is a possibly not-best-practice way of using Powershell’s wonderful help system to store bits of reference material.

The problem

I’m moving a WordPress blog to Hugo, which uses Markdown, but I’m struggling to remember the Markdown syntax. It’s not difficult, but I’m getting old and I get confused with Twiki syntax.

In any case this ‘technique’ could be used for anything.

I could equally well just store the content in a big text file, and select-string it….but this is more fun 🙂

The content

In this instance I only need a few lines as an aide-memoire:

    ## The second largest heading (an <h2> tag)
    > Blockquotes
    *italic* or _italic_
    **bold** or __bold__
    * Item (no spaces before the *) or
    - Item (no spaces before the -)
    1. Item 1
      1. Furthermore, ...
    2. Item 2
    `monospace` (backticks)
    ```` begin/end code block
    [A link!](

create a module

The module path is given by:


Mine is:

C:\Users\matty\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\

Pick one of this folders to create your module in and do this:

mkdir C:\Users\matty\Documents\WindowsPowerShell\Modules\QuickReference

Then create a dummy Powershell module file in the folder

notepad C:\Users\matty\Documents\WindowsPowerShell\Modules\QuickReference\QuickReference.psm1

The content of the module file is throwaway:

function dummy {write-output "This is a dummy"}

create the help file(s)

Create a language-specific folder for the help files

mkdir C:\Users\matty\Documents\WindowsPowerShell\Modules\QuickReference\en-US\

Edit a file called

notepad C:\Users\mpenny2\Documents\WindowsPowerShell\Modules\QuickReference\en-US\

My content looked like this:


    Syntax for Markdown 


    ## The second largest heading (an <h2> tag)
    > Blockquotes
    *italic* or _italic_
    **bold** or __bold__
    * Item (no spaces before the *) or
    - Item (no spaces before the -)
    1. Item 1
      1. Furthermore, ...
    2. Item 2
    `monospace` (backticks)
    ```` begin/end code block
    [A link!](

Use the help

I can now do this (I’ll import the module in my $profile):

PS C:\Windows> import-module QuickReference

Then I can access my Markdown help from within Powershelll

PS C:\Windows> help Markdown

    Syntax for Markdown 


    ## The second largest heading (an <h2> tag)
    > Blockquotes
    *italic* or _italic_
    **bold** or __bold__
    * Item (no spaces before the *) or
    - Item (no spaces before the -)
    1. Item 1
      1. Furthermore, ...
    2. Item 2
    `monospace` (backticks)
    ```` begin/end code block
    [A link!](

extracting post details from wordpress xml dump with powershell

Get the xml into a variable

[xml]$xmla = get-content D:\repair_websites\salisburywiltshireandstonehenge.wordpress.2015-10-03.xml                       

Extract the details

select-xml -xml $xmla -xpath "//channel/item" | select -expandproperty node | ? post_type -ne "attachment" | select title  

gives the following:

Road names beginning with 'N'
Road names beginning with 'O'
Road names beginning with 'P'
Road names beginning with 'Q'
Road names beginning with 'R'
Road names beginning with 'S'
Road names beginning with 'T'
Road names beginning with 'U'
Road names beginning with 'V'
Road names beginning with 'W'

The properties of the expanded node are:

For example:

select-xml -xml $xmla -xpath "//channel/item" | select -expandproperty node | ? post_type -ne "attachment" | ? title -like "*Ramone*"


title          : 3rd June 1977 - the Ramones visit Stonehenge. Johnny stays on the bus
link           :
pubDate        : Tue, 04 Nov 2014 12:33:09 +0000
creator        : creator
guid           : guid
description    : 
encoded        : {content:encoded, excerpt:encoded}
post_id        : 9267
post_date      : 2014-11-04 12:33:09
post_date_gmt  : 2014-11-04 12:33:09
comment_status : open
ping_status    : closed
post_name      : 3rd-june-1977-the-ramones-visit-stonehenge-johnny-stays-on-the-bus
status         : publish
post_parent    : 6624
menu_order     : 3
post_type      : page
post_password  : 
is_sticky      : 0
postmeta       : {wp:postmeta, wp:postmeta, wp:postmeta, wp:postmeta}

To get the actual content of the post:

select-xml -xml $xmla -xpath "//channel/item" | select -expandproperty node | ? post_type -ne "attachment" | ? title -like "*Ramone*" | select -ExpandProperty encoded | fl


#cdata-section : <a href=""><img src="" alt="Joey Ramone - 'visited' 
                 Stonehenge" width="320" height="455" class="alignright size-full wp-image-9702" /></a>On either the 3rdIn 'On the Road with 
                 the Ramones', Monte A. Melnick says that the visit occurred 

                 <blockquote>'On the '77 tour we had a day off and noticed Stonehenge was on the way'[URL <a href="
                 id=N7m8AwAAQBAJ&lpg=RA1-PR24&dq=ramones%20stonehenge&pg=RA1-PR25#v=onepage&q=ramones%20stonehenge&f=false">'On the Road with the 
                 Ramones', by By Monte A. Melnick, Frank Meyer</a>].</blockquote>

                 This would have been when the Ramones were travelling back from Penzance to Canterbury - the free day being June 3rd [<a href="">Wikipedia List Of Ramones Concerts</a>] or possibly the 
                 4th June 1977, the Ramones visited Stonehenge.

                 Pic: By en:User:Dawkeye [<a href="">GFDL</a>, <a href="">CC-BY-SA-3.0</a> or <a href="">CC-BY-SA-2.5</a>], <a href="">via Wikimedia Commons</a>


                 <a href="
                 ge&f=false" title="
                 20stonehenge&f=false">I Slept with Joey Ramone: A Family Memoir By Mickey Leigh</a>

                 <a href="
                 onehenge&f=false" title="
                 e&q=ramones%20stonehenge&f=false">On the Road with the Ramones By Monte A. Melnick, Frank Meyer</a>

                 <a href="
                 q=+stonehenge" title="
                 withinvolume&q=+stonehenge">A Time to Rock: A Social History of Rock and Roll by David P. Szatmary</a>

#cdata-section : 

powershell to recursively spool out code in markdown format

A one-liner to recursively gather code from sub-folders and then output it in a Markdown-style

$Text = foreach ($file in $(dir .\themes\hyde -recurse -exclude "*.png" | ? attributes -ne 'Directory' | select fullname)) 
    [string]$filename = $file.fullname
    write-output "`#`#`# $filename"
    write-output "````````"
    get-content $filename
    write-output "````````" 

$Text > x.txt

Produces output a like this:


Description = ""
Tags = ["Development", "golang"]
Categories = ["Development", "GoLang"]
menu = "main"


{{ partial "head.html" . }}
<body class="{{ .Site.Params.themeColor }}">

{{ partial "sidebar.html" . }}

<div class="content container">
<ul class="posts">
{{ range .Data.Pages }}

error 740 running DISM

As the error message says, if you get Error 740

PS C:\Users\matty> DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:z:\sources\sxs

Error: 740

Elevated permissions are required to run DISM.
Use an elevated command prompt to complete these tasks.

…you just have to run your Command Prompt or Powershell window ‘as Administrator’. i.e. right-click on the icon and select ‘Run as administrator’

PS C:\Windows\system32> DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:z:\sources\sxs

Deployment Image Servicing and Management tool
Version: 6.3.9600.17031

Image Version: 6.3.9600.17031

Enabling feature(s)
The operation completed successfully.
PS C:\Windows\system32>

how I sketchnote

wsd-logo-600pxJanuary 11th has been designated as World Sketchnote Day. Out of sheer perversity. I thought rather than doing a sketchnote, I thought I’d type something in plain text!

A couple of people have asked about the way I do sketchnotes, so this seems like a good day to post it.

I read the book – reading Mike Rohde’s ‘The Sketchnote Handbook’ is a big jump-start. It’s quick and fun to read and it’s a lovely book. I read it in a couple of hours. Any other words of wisdom I might have pale into insignificance besides ‘go and read Mike’s book‘.

A4 paper – I now do all my Sketchnoting on plain A4 paper. It’s a good size for an hour’s talk, it’s cheap, it’s easy to scan and I don’t often run out of it.

Squared paper – I created an A4 grid in Word and put the blank sheet on top of that. This makes the notes a bit less scruffy.

Erasable ink – I use Uniball Frixion pens. I don’t rub much out, but it’s handy to be able to do so. Pencil doesn’t scan as well as ink.

Agendas are useful – if I can find the slides for a talk I’ve found it useful to have the agenda handy, so that I know when the speaker has moved on to a new topic.

No overdubs – I do 99% of the sketchnote-ing of talks live, in real-time. This is partly because I’m lazy, but it also means that any benefits I get from sketchnoting are essentially free. Apart from the time it takes to scan and post, the sketchnoting doesn’t take any extra time beyond the time I’m spending attending the talk.

Visual vocabulary – Mike Rohde uses the phrase ‘visual vocabulary’ for the collection of things you can draw fairly quickly when you need to. Because I’m a bit of a nerd, I’m collecting these on a visual vocabulary page. The page is useful to remind myself how I’ve drawn things in the past…but I’m thinking I’m might convert it to something I can print on a couple of pieces of paper.

‘Learning’ from others – I’ve copied some ways of drawing things from other sketchnoters. I sometimes copy clip-art or icons or logos too.

Webcasts are great – I do sometimes feel self-conscious sketchnoting at a conference. Webcasts avoid this issue!

Tedtalks aren’t great – a lot of people practice sketchnoting Tedtalks with very good results. This doesn’t work so well for me. I’ve tried it a couple of times, but found I was continually re-winding the talk and hunting down stuff to sketch. A 20-minute talk took me getting on for two hours to sketchnote. And it still wasn’t finished.

Not drawing the presenter – early on I used to do a sketch of the person who was doing the talk. This probably isn’t a good idea unless you’re a good artist and can make it flattering… or unless you know the presenter and know they won’t mind their appearance being reduced to, say, a bald head and glasses.

Publishing – I started putting the sketchnotes on twitter as soon as I’d read the book. It didn’t seem good enough to publish, but if I’d waited until it did I’d have never shown it to anyone. I would do sketchnotes anyway, but I’ve gained a lot through putting them out there.

I’m not very good at – color, drawing, different formats, not trying to capture everything.

Practice – I do practice some of the drawings in odd moments when I have a pen and paper to hand. A lot of doodling is done in meetings! Also, sometimes while I’m sketchnoting I’ll try out, say, drawing a pig on a bit of scrap paper, before putting it into the sketchnote.