SharePoint stsadm.exe and the infamous "Command line error"

The SharePoint command-line utility stsadm.exe was driving me crazy for the last two days. I'm automating all kind of this from PowerShell scripts, but I got the error "Command line error" while I was absolutely sure that what I was doing was correct. I did stsadm.exe -o deletesolution foobar.wsp. And the problem was: character encoding...

First I thought it was a problem with the way I executed this command from PowerShell. When I copied over the command to a different script it worked. What!!!??? Then I copied it over to the cmd.exe shell on the command line and I got the same error.

I started searching on Google and came accross this blogpost. It said it had something to do with encoding. The blog post also pointed to this blog post where people responded in the contents with the most hillarious solutions like:

If I type STSADM.EXE it works, while STSADM.exe does not work, or that a solution file must be in the same folder as stsadm.exe. Read the comments, it is fun how far off people can get.

Another post mentioning the problem is this discussion thread.

The problem happened to be in the encoding. One way or the other it is possible to get different encodings while typing in the same command multiple times in the same cmd.exe shell. Don't ask me how.

If you have problems, type your text in an editor like Notepad++, and switch between "Encode in ANSI" and "Encode in UTF-8" (it is under the Format menu in Notepad++). You see (sometimes)the dash(-) in stsadm -o command... change from '-' to a strange little block... There is the problem. The dash is not always a dash, it is a hyphen... And stsadm then thinks that no command is specified. Remove the strange block, type a hyphen while is UTF-8 encoding, copy that and bingo!! It works.

Ok, how to repeat this:

  1. Start Notepad++, set encoding to ANSI
  2. Make sure the path to stsadm.exe is in your path environment variable (or use full path)
  3. Type stsadm -o deletesolution foobar.wsp
  4. Start cmd.exe
  5. Copy the text over and press enter: voila, Command line error.

The strange thing is that even if you remove the dash (-), and type it again, it still gives errors. I have no clue why.

This dash/hypen thing is a common problem if you search Google, for more info see for example:


Comments have been disabled for this content.