63

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.) Apr 21, 2015 at 16:58
  • @RahulLodha This problem could be due to pathext variable problem. See superuser.com/questions/675006
    – X10
    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.
    – James
    Dec 14, 2021 at 23:08

5 Answers 5

101

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"
4
  • 4
    It worked. i had to restart visual studio after path change. Thank You! :) Apr 21, 2015 at 17:30
  • 2
    Glad it worked. Strange that it was missing though. I've always seen it populated by default.
    – Jon Tirjan
    Apr 21, 2015 at 17:31
  • What worked for me was C:\WINDOWS\System32\WindowsPowerShell\v1.0\ Apr 27, 2021 at 10:31
  • 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.
    – qaziqarta
    Aug 4, 2022 at 5:56
10

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

0
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.

1
  • The approved solution did work for me, but this was really the root cause.
    – molbalga
    Jan 19, 2021 at 10:21
2

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

0

try

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

might require \\ instead of \.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.