Invoking files with spaces in PowerShell

I needed to run an executable multiple times with different parameters and felt that it would be easier to write the script in PowerShell than in a command script.  The biggest challenge I ran into was running the executable because the path to it has spaces in it (C:\Program Files\etc).  Add to that I wanted to put the whole command in a string first and then invoke the string and this turned out to be a lot more challenging than I had hoped.

To invoke an executable (or any file, for that matter) that has spaces in it, you need to use quotes and then use the ampersand (&) operator.  For example, if you want to invoke a file called C:\My File.cmd, you would have to invoke it like so:
& '.\My File.cmd'
If you wanted to pass parameters, you would do this:
& '.\My File.cmd' foo
So far so good.  Things are a bit different, however, if you want to invoke a command in a variable.  To do that, you must use the Invoke-Expression cmdlet, like so:
$_cmd = "'.\My File.cmd' foo"
Invoke-Expression "& $_cmd"

$_cmd = "& '.\My File.cmd' foo"
Invoke-Expression $_cmd

PowerShell is certainly powerful, but this was far from obvious.  Fortunately there are others who have posted about this.  You can check out the resources I’ve listed below for a couple webpages that helped me.


Comments (1)

Cometdocs File Converter

I just ran across a free online file converter called Cometdocs.  This free online service allows you to convert different types of files to multiple other file types, including PDF.  You can also compare two files and get the results.

All you do is browse to a file on your disk, select the destination file type, then type an email address of someone to send the results to.  The recipient receives an email with a link to a page which allows them to download the resulting file.

The service keeps your file on their server for a limited amount of time (it wasn’t obvious to me how long in my brief perusal of their site) but if you want it to be stored longer you can sign up for a free account.

Very cool service!

Comments (1)

Failed to update headers in Outlook 2007

I use Outlook 2007 pretty rigorously.  I host my own Exchange Server, so that’s my primary mailbox.  I include multiple other mailboxes (such as my wife’s, my kids’, etc.).  Finally, I use IMAP to connect to my company’s Exchange Server so I can use a single interface for accessing all my email.  I’d use an Exchange connection if I could, but the Office team at Microsoft, in their infinite wisdom, decided this wasn’t something anyone should do.  Grrr.

Anyway, a week or two ago, I started getting an error message that looked like this every time I clicked on one of my IMAP folders:

Failed to update headers in Outlook 2007

An IMAP command failed.
        Protocol:  IMAP
        Server:     my.server
        Port:         143

I finally got myself unburied enough to investigate and found a very helpful post – a forum actually – that described how to solve this problem.  Microsoft provides the SCANPST tool which will scan and repair your personal store (.pst) and offline store (.ost) files which contain the mail data for your mail accounts and profiles.  Here are the steps to solve this problem:

  1. Close Outlook.
  2. Go to \Program Files\Microsoft Office\Office12\ and run SCANPST.EXE as Administrator.
  3. Browse for your .PST and .OST files.  If you haven’t changed the location, you will find them at
    on Windows Vista or
    \Documents and Settings\AppData\Local\Microsoft\Outlook\
    on Windows XP.
  4. Scan and repair all errors.  I had to do this 2 or 3 times for each file.  Be default the tool will save a backup file.  The second or third time you run it on a file it will want to overwrite the backup file it wrote the last time you ran it, so either change the name or answer yes to overwrite it.
  5. Restart Outlook.

But wait – this didn’t work for me.  No matter how many times I used SCANPST.EXE, it didn’t solve the problem.  My problem turned out to be caused by a corrupted meeting request in my inbox.  As soon as I deleted the meeting request, the problem went away.  I only found it by connecting to my inbox using Outlook Web AccessW when I discovered I couldn’t view it from there either.  What would have been nice is to have found a tool to scan my Exchange inbox.

Oh well.  At least I solved my problem.  I’d be interested to know if you find other solutions to this problem, particularly one that involves a tool that scans Exchange Server mailboxes.


Comments (11)

Changing the WordPress Table Prefix

WordPress allows you to specify the prefix used for naming all your tables.  Unfortunately, there are several places where it hard-codes the full names of the tables, including the prefixes, so you can’t just rename the tables.  You also must modify values in the tables.  I’ve had to do this a few times recently as I’ve reorganized my sites, so I figured it was time to write an article about it.

Here are the steps to change the prefix for your WordPress site.  I use phpMyAdmin v3, but you can use any tool that allows you to manage your MySQL databases.  These steps assume you are changing your prefix from prefix1_ to prefix2_.

  1. Rename all the tables beginning with prefix1_ to prefix2_.  You do this in phpMyAdmin by doing the following:
    1. Click on the database name.
    2. Click on each table whose name begins with prefix1_ in turn.
    3. Click on the Operations tab.
    4. In the Table options section to the left, replace prefix1_ with prefix2_ in the table name and click Go.
  2. Rename the values in the meta_key column of the wp_usermeta table using this SQL command:
    UPDATE `prefix2_usermeta` SET `meta_key` = REPLACE( `meta_key` , 'prefix1_', 'prefix2_' );
  3. Rename the values in the option_name column of the wp_options table using this SQL command:
    UPDATE `prefix2_options` SET `option_name` = 'prefix2_user_roles' WHERE `option_name` ='prefix1_user_roles' AND `blog_id` =0;

It’s possible that some plugins may need additional attention.  You may still need to deactivate and then re-activate some plugins, and you may even need to deactivate some plugins, delete their options from the prefix2_options table, then re-activate them.  Finally, you may find that the prefix is embedded in other places as well.

I found the following blog post to be very helpful as I was tracking down this problem:

Comments (1)

The “Get Started With Office Live” window keeps popping up

I have Office 2007 installed on a Windows Vista system and I installed the optional Office Live add-in offered to me through Windows Update.  The first time you start Word, Excel, or PowerPoint, it is supposed to pop up a getting started window to allow you to get more information on Office Live, but there is a checkbox in the lower left corner allowing you to prevent the window from being displayed again.  The problem is, the checkbox doesn’t always work.  Microsoft published a KB article on it and in that article says this condition happens when the person running Office isn’t the person who installed the add-on.  The problem is that it is looking for a registry key that doesn’t exist in the current user’s registry and therefore it doesn’t write the value which allows the popup to honor the setting of the checkbox.

The fix is easy.  Just define an OfficeLive registry key at HKEY_CURRENT_USER -> Software -> Microsoft.  This worked for me.  Kind of a sloppy error, though, if you ask me.


Leave a Comment

Upgrading to IE8 breaks debugging with Visual Studio 2005

Since Microsoft published IE8 as a Windows Update and my boss said he upgraded to it, I figured it was safe to upgrade to it as well.  I’ve been enjoying the changes for a couple days now, but when I attempted to debug an ASP.NET application with Visual Studio 2005, it would no longer stop at a breakpoint.  Pretty frustrating if you ask me.  I’ve found a few articles online describing problems, most of which I haven’t encountered yet.  You may want to implement all these workarounds.

The problem I was having appears to be related to how IE8 uses multiple processes.  Apparently VS 2005 doesn’t know which process to attach to.  Here are three solutions:

  1. Don’t have IE8 running at the time you want to debug.  This worked for me.
  2. Modify the registry as described in the second link above.  This worked for me as well.  Here are the steps:
    1. Open RegEdit
    2. Browse to HKEY_LOCAL_MACHINE -> SOFTWARE -> Microsoft -> Internet Explorer -> Main
    3. Add a DWORD value called TabProcGrowth with a value of 0
    4. Turn off protected mode browsing in IE (Security page of Internet Options) if you are running on Vista or newer.
  3. Uninstall IE8 to revert back to IE7.  I don’t really want to do this though.  I’ve grown particularly fond of a few of the new features in IE8, such as previous session restore (although I wish it would allow me to restore more than just the last session) and improvements in search.

I don’t know if this is a problem with VS 2008, but some of the articles seem to imply it only applies to VS 2005.  Maybe it’s time to upgrade Visual Studio :-)

Comments (55)

Determining what a SQL Server connection is doing

Quick note here describing how to find out what a connection to a Microsoft SQL Server is doing.  First you need to find the connection.

Display current connections

Use the sp_who2 stored procedure to find the current connections.  Use the following information to determine the connection of interest.

  • SPID – The ID of the connection.  You will need this in the next step.
  • Status – Typically this will be RUNNABLE, but occasionally it will be sleeping or SUSPENDED.
  • Login – Typically the user who’s connection you are investigating (e.g. your own).
  • HostName – The name of the computer making the connection.
  • DBName – The database to which the connection is made.
  • Command – The command being executed.  Only displays the high-level command (e.g. SELECT INTO, DELETE, etc.).

Note that you can also specify an SPID to the sp_who2 stored procedure to get information about a specific connection.

Display the command

Use the following command to display the full SQL command being executed (where 53 is the SPID for the connection).
dbcc inputbuffer(53)
This command will display a result row with three columns:

  • EventType
  • Parameters
  • EventInfo

EventInfo contains the information you are looking for.

Leave a Comment

Using PHP mail function with locked-down SMTP server

I host my own Exchange server and had accepted the restriction that I couldn’t use the PHP mail() function thinking it was an incompatibility with IIS.  It turns out, however, that my Exchange server (like most Exchange servers) requires a username and password to work.

I found a user on a forum that solved this problem so that he could use Gmail or an external SMTP Server that required SSL, and he wrote this up in a terrific article describing all the gory details.

Once I downloaded the package from the article, I made the following changes to the sendmail.ini file:

  • Set smtp_server to point to my server.
  • Set the smtp_port back to 25 (it was set to 587 to work with Gmail).
  • Set default_domain for addresses that don’t specify it.
  • Set auth_username and auth_password to a valid email address and the password for that email address – this is the key right here that makes it all work.
  • Commented out force_sender.  I don’t want it always coming from a single username since I host multiple sites managed by different users.

Then I had to change my php.ini file.  I commented out everything but sendmail_path.  I tested this and it works great.

Note that the original author of the fake sendmail (Byron Jones) has released bug fixes, so you may want to download his later versions instead.


Comments (6)

Testing an SMTP Server

Microsoft has a good article on testing an SMTP server using Telnet.  I’ve summarized the steps here using the following information:

SMTP server name
Source domain name
From email address
Recipient email address

Here is the summary of commands and responses.  Remember to press <ENTER> after each command.

Command Response
telnet 25 220 Microsoft Exchange Internet Mail Connector <version number of the IMC>
RCPT 250 OK - Recipient
DATA 354 Send data. End with CRLF.CRLF
Subject: test message  
This is a test message.  You will not see a response from this command.  
. 250 OK
QUIT 221 closing connection

Leave a Comment

Auto Highlighting from an SSI Navigation Menu

Recently on I was in the process of converting the side navigation menu on the Strategy Guide sections to a Server Side IncludeW file.  Before making the switch to an SSI, the guide was copy and pasted between each page to provide the following:

This solution felt very heavy weight though. In the comments was another interesting idea:

var x = document.getElementsByTagName('a');
for (var i=0; i < x.length; i++)
{ if (x[i].href == location.href) x[i].className += 'onstate'; }

The general idea of cycling through the available anchors to find the appropriate one for the page we are on was a good one.  Unfortunately, we don’t want to change all the links on a page and none of the articles mentioned at all how or when to get it to execute.

What I needed was a script to add to the INC file for the nav menu that would only look at the relevant anchors within the guide, execute when the list is first loaded, and not require any special code on the pages that include it.  What I ended up with was the following:

<!-- Start: Guide Menu -->
<div class="guideMenu" id="guideMenu">
 <div id="guideTitle">Strategy Guide</div>
 <p><a class="guideItem" href="">Getting Started</a></p>
 <p><a class="guideItem" href="">The Basics</a></p>
 <p><a class="guideItem" href="">Rollin' a Bankroll</a></p>
 <p><a class="guideItem" href="">Usin' Skill Points</a></p>
 <p><a class="guideItem guideItemLocked">Doin' the Job</a></p>
 <p><a class="guideItem guideItemLocked">Property Moguls</a></p>
 <p><a class="guideItem guideItemLocked">Fightin' and Robbin'</a></p>
 <p><a class="guideItem guideItemLocked">Game Design Suggestions</a></p>
<!-- Entry Highlighting Script -->
<script type="text/javascript">
var menuDiv = document.getElementById('guideMenu');
var anchors = menuDiv.getElementsByTagName('a');
for (var i = 0; i < anchors.length; i++)
    if (anchors[i].href == location.href)
        anchors[i].id = 'guideSelection';
<!-- End: Guide Menu -->

Very simply, the original DIV for the menu was maintained, a specific ID was added so the script would target just the menu and not other links on the page. From there, just add a script block after the menu (otherwise the getElement calls will not work in all browsers) and leave the script outside of any function definition so it gets executed as the page gets parsed.

The script itself grabs the menu DIV so it can operate on only its child members and then collects all the anchors.  It cycles through the anchors until it finds the one that matches the page it is currently on and adds our special selection ID.  The solution would also work with classes by appending a new class name to the existing list on the element.

The final file is then able to be included in any of our guide pages and nothing special needs to exist on the page at all for the highlighting to be accurate.  Hopefully this will help others working outside of PHP and ASP to have a simple way to break their navigational elements out from the individual pages and in to INC files where it is much more simple to keep them updated.

Leave a Comment

Page 4 of 16« First...23456...10...Last »