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

WindowsPowershellVisual Studio-2013

Windows Problem Overview


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

Windows Solutions


Solution 1 - Windows

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

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

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

Solution 3 - Windows

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.

Solution 4 - Windows

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

Solution 5 - Windows

try

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

might require \\ instead of \.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRahul LodhaView Question on Stackoverflow
Solution 1 - WindowsJon TirjanView Answer on Stackoverflow
Solution 2 - WindowsMostafa WaelView Answer on Stackoverflow
Solution 3 - WindowsallohaView Answer on Stackoverflow
Solution 4 - WindowsAlexView Answer on Stackoverflow
Solution 5 - WindowsArif TestView Answer on Stackoverflow