PowerShell – Error Message – “Exception calling “Load” with “1” argument(s): “‘=’ is an unexpected token. The expected token is ‘;’. “

Background

Trying to run a powershell script, but I am being greeted with the error message:

 

Exception calling "Load" with "1" argument(s): "'=' is an unexpected token.
The expected token is ';'. Line [line-number], position [position]."

 

Code

From reviewing the error message and line number, the offending code line is:


# Declare XML Object
$xmlConfig = New-Object -TypeName XML

$configFile = 'websitelist.config'
# Load Configuration File
$xmlConfig.Load($configFile)

 

Fix

To fix,  I will suggest the following:

 

Review XML File

Review XML file using an XML Editor.  There are plenty of free ones.  I am currently using XML Copy Editor.  It is available from http://xml-copy-editor.sourceforge.net/

 

Check For Well-Formedness

We get an error when we tested our XML Config file.

Image:

NotWellFormed

Textual:


Error at line 54, Column 151 : not well-formed (invalid token)

 

 

Remediate

The problematic element in the XML file contains an HTTP/Web URL.

To fix, I need to Encode it:

There are plenty of free XML Encoders on the .Net.  List of good ones includes:

 

 

Free Formatter

There are plenty of options on this web site:

XMLEscape

We will choose “String Escaper & Utilities \ XML Escape”.

 

We will enter the “unescaped” URL, choose the “Escape” option, and get back an escaped XML.

 

Take that Escaped URL, to our editor and we are good.

 

Summary

Unfortunately, this is what happens when one finds himself like “Johnny Football” and one only does this things on the weekend.

 

 

Leave a Reply

Please log in using one of these methods to post your comment:

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