为何执行当前目录PowerShell脚本时提示找不到其他路径的脚本文件?
PowerShell脚本执行错误原因分析
问题重现
执行的命令:
PS C:\Users\myusernam\myfolder> .\file_name.ps1
收到的错误提示:
&: The term 'C:\scripts\file_name.ps1' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
错误原因
- 脚本内部硬编码了错误路径:你运行的
.\file_name.ps1脚本里,大概率调用了C:\scripts\file_name.ps1这个不存在的文件,或者脚本逻辑错误地将目标路径指向了C:\scripts目录,而非当前工作目录。 - 脚本配置绑定错误路径:如果该脚本是通过快捷方式、任务计划等方式启动,可能配置里绑定了
C:\scripts这个错误路径,导致PowerShell去错误位置查找执行文件。 - 文件名或目录拼写错误:确认当前目录下的脚本文件名是否完全正确,同时检查
C:\scripts目录是否存在、是否包含该脚本文件。
内容的提问来源于stack exchange,提问作者HrkBrkkl
相关产品推荐
相关产品推荐

