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

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 ==========

Solution 1:

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"

Solution 2:

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