Powershell'不被识别为内部或外部命令,可操作程序或批处理文件

Rah*_*dha 30 windows powershell visual-studio-2013

我正在尝试运行powershell -Command来执行一个powershell文件作为Visual Studio 2013中的后期构建事件但是我得到了
Powershell' is not recognized as an internal or external command, operable program or batch file

输出窗口和错误

Powershell -Command exited with code 9009 error
Run Code Online (Sandbox Code Playgroud)

完整错误消息:

'Powershell' is not recognized as an internal or external command,
10>  operable program or batch file.
10>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(4429,5): error MSB3073: The command "echo "C:\dev\tfs\Main\Shared\AggregationComponents\GenerateSchema.cmd"
10>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(4429,5): error MSB3073: call "C:\dev\tfs\Main\Shared\AggregationComponents\GenerateSchema.cmd"
10>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(4429,5): error MSB3073: echo "Move the PhoenixData namespace schema suffixing it"
10>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(4429,5): error MSB3073: Powershell -Command "C:\dev\tfs\Main\Shared\AggregationComponents\MoveAndRenameXsds.ps1 'C:\dev\tfs\Main\Shared\AggregationComponents\bin\Debug\' 'C:\dev\tfs\Main\Shared\AggregationComponents\..\PublishedAnalyticsXsds' '.Aggregation'"" exited with code 9009.
========== Rebuild All: 8 succeeded, 1 failed, 1 skipped ==========
Run Code Online (Sandbox Code Playgroud)

Jon*_*jan 46

听起来你错过了一个环境变量.

将其添加到您的Path环境变量:

%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
Run Code Online (Sandbox Code Playgroud)

要么

将您的脚本更改为:

%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe -Command "your command"
Run Code Online (Sandbox Code Playgroud)

  • 有效.路径改变后我不得不重启visual studio.谢谢!:) (2认同)
  • 很高兴它起作用了。奇怪的是它虽然不见了。我一直看到它默认填充。 (2认同)

Mos*_*ael 5

您只需要将其添加到您的环境变量中,只需遵循以下两个简单步骤:

1.在搜索栏中写入env

右键单击开始按钮 -> 系统 -> 高级系统设置 -> 环境变量... -> 选择 PATH

2.点击新建按钮,添加如下路径:

C:\WINDOWS\System32\WindowsPowerShell\v1.0\

或者 %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\


在搜索栏中写入 env 选择路径 单击确定