70

I am trying to run a powershell -Command to execute a powershell file as a post build event in Visual studio 2013 But i am getting

'Powershell' is not recognized as an internal or external command, operable program or batch file

error on output window and

Powershell -Command exited with code 9009 error

Full Error Message:

'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 ==========
3
  • The unmatched quotation marks are suspicious. Are you sure you copied it correctly? Please share the actual command line you are trying to execute. (Also verify that it is on your PATH.) Commented Apr 21, 2015 at 16:58
  • @RahulLodha This problem could be due to pathext variable problem. See superuser.com/questions/675006 Commented Sep 18, 2015 at 2:54
  • An old thread I know, but I had this issue recently using the JetBrains WebStorm CLI (similar to VS Code) and turns out that if I used Windows Command Prompt as Administrator it worked fine. Commented Dec 14, 2021 at 23:08

6 Answers 6

115

Sounds like you're missing an environment variable.

Add this to your Path environment variable:

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

OR

Change your script to this:

%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe -Command "your command"
Sign up to request clarification or add additional context in comments.

It worked. i had to restart visual studio after path change. Thank You! :)
Glad it worked. Strange that it was missing though. I've always seen it populated by default.
What worked for me was C:\WINDOWS\System32\WindowsPowerShell\v1.0\
I had to move the path %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\ from the System environment list box to the User environment list box, as per this answer: superuser.com/a/1034020 . Otherwise the %SYSTEMROOT% part was not expanding to actual path.
BERJAYA
This is working and , Have to restart visual studio after path change. Otherwise will show the same error- default path- C:\WINDOWS\System32\WindowsPowerShell\v1.0\
18

You only need to add it to your environment variables, just follow the following two simple steps:

1.write env in the search bar

or Right click start button -> System -> Advanced system settings -> Environment Variables... -> Select PATH

2. click on the new button and add the following path:

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

or %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\


write env in the search bar

choose path

click Ok

Comments

4

Remove BOM byte from the beginning of batch file or convert it's encoding to ANSI. BOM treats system to think you use unavailable command.

The approved solution did work for me, but this was really the root cause.
2

My mistake was just that I forgot to run Visual Studio / command prompt as an Administrator.

Comments

0

try

'%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe tracert google.com'

might require \\ instead of \.

Comments

0

Old question, but I had this issue today.

I wrote a batch script that subsequently executes a Powershell script, and accidentally used %path% as a local variable, to store the path of some unrelated file, in the batch script.

However, using %path% as a local variable will quietly override your (very important) environment %PATH% variable, which happens to include the path to powershell.exe.

Thankfully, this change is not permanent (unless you used setx in the batch file).

Comments

Your Answer

Draft saved
Draft discarded

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.