我有一个“古怪”的PowerShell问题,我希望有人能帮我解决。这可能不是一个真正的PowerShell问题,但我已经遇到了两次,而且两次都是使用PowerShell。
今天,我下载了PSUnit。我按照安装说明操作,其中包括将profile.ps1复制到我的PowerShell配置文件目录中。文件中的第一行是:
$PSUnitPath = "D:\Data\PSUnit"完成安装后,当我在PowerShell ISE中打开PSUnit测试时,收到以下错误:
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注意,它在所有字母之间插入了一个空格。当我在文本编辑器中打开文件时,多余的空格不在那里。
只需打开Powershell命令窗口时,即不涉及ISE时,也会出现此错误。
我不认为这是PSUnit的问题。我以前在一个不涉及PSUnit的不同PowerShell程序上有过一次这样的经历。当时我解决这个问题的唯一方法是打开一个新文件,然后重新键入PowerShell程序。
发布于 2015-03-13 22:52:11
这是一个编码问题。文件采用双字节字符编码(例如UCS-2高字节顺序),但ISE将其解释为单字节字符(例如UTF-8)。通常,当字节顺序标记( Byte Order Mark,BOM)丢失或者编辑器或程序不理解双字节编码时,就会出现这种情况。
在Notepad++中打开该文件,然后使用编码菜单将其更改为UTF-8。没有BOM的UTF-8也可以。
https://stackoverflow.com/questions/29035096
复制相似问题