0

I'm having a "wacky" PowerShell problem that I'm hoping someone can help me resolve. It may not really be a PowerShell issue but I've hit it twice and both times using PowerShell.

Today, I downloaded PSUnit. I followed the install instructions which includes copying the profile.ps1 into my PowerShell profile directory. The first line in the file is:

$PSUnitPath = "D:\Data\PSUnit"

After completing the install, when I open my PSUnit test in the PowerShell ISE, I get the following error:

The term ' $ P S U n i t P a t h ' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct an
d try again.
At C:\Users\sfhostingadmin.SCRUMDOMAIN\Documents\WindowsPowerShell\profile.ps1:3 char:24
+  $ P S U n i t P a t h  <<<<   =   " D : \ D a t a \ P S U n i t "   # M o d i f y   t h i s   p a t h   t o   m a t c h   y o u r   l o c a l   P o w e r S h e l l   i n s t a l l a t i o n   p a t h 
    + CategoryInfo          : ObjectNotFound: ( $ P S U n i t P a t h :String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Notice, it inserted a space between all of the letters. When I open the file in a text editor, the extra spaces are not there.

I get this error when simply opening the Powershell command window too i.e. where the ISE is not involved.

I don't think this is a PSUnit issue. I had this once before on a different PowerShell program where PSUnit was not involved. The only way I got around it back then was by opening a new file, and re-typing the PowerShell program.

1
  • Have you checked to see whether this is a Unicode vs Ascii issue? Commented Mar 13, 2015 at 14:52

1 Answer 1

2

This is an encoding issue. The file is two-byte character encoding (e.g., UCS-2 big endian), but ISE is interpreting it as a single byte character (e.g., UTF-8). Usually this happens when the Byte Order Mark (BOM) is missing or the editor or program doesn't understand two-byte encoding.

Open the file in Notepad++, and use the Encoding menu to change it to UTF-8. UTF-8 without BOM is fine, too.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.