I am running a SharePoint PowerShell script on an hourly basis from one of the farm servers. It was running well for more than two months. Then one of my colleagues came over and asked me to call couple of exes that he has written. Let us suppose his exe is called MyExe.exe. And then the fun began. Here is what I tried from my PowerShell script:

  • .\MyExe.exe Parameter
  • & .\MyExe.exe Parameter
  • Start-Process MyExe.exe Parameter
  • Invoke-Expression MyExe.exe Parameter

When I ran my script from the SharePoint PowerShell admin console, it worked just fine. However, Windows task scheduler complained stating:

The term ‘MyExe.exe’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

MyExe.exe reside in the same location my PowerShell script is at.

After hours of frustration and head scratching and hair pulling, one other colleague of mine pointed that may be you should try calling the exe with its entire path in front of it, something like:

& “F:\MyFolder\MyExe.exe” Parameter

And there you go. Everything started working just fine.