Error: The term './RunCommandLine.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program

Mark Fulton picture Mark Fulton · Sep 10, 2015 · Viewed 37.7k times · Source

We are using Microsoft Release Management 2013 to deploy to Dev/Test/Prod. The Build/Deploy Server is MS2012. The Application Servers are MS2008. I had it working and deploying but then yesterday I started getting this message. All its doing is using the 'Run Command Line' to run a batch file on the Application Server that makes a backup, sets windows services startup type, stops services, etc. If I run the batch file directly on the Application Server it runs just fine. I added more detailed logging per this article but no additional information was gathered in order to debug. Powershell has not been updated lately on the servers either.

http://blogs.msdn.com/b/visualstudioalm/archive/2013/12/13/how-to-enable-detailed-logs-and-collect-traces-from-various-release-management-components.aspx

Anyone know where the *.ps1 files are supposed to be? I searced local and server but found nothing. Anyone ever encounter this?

Error Message:

The term './RunCommandLine.ps1' 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.
At line:1 char:21
+ ./RunCommandLine.ps1 <<<<  -FilePath '\\unc-path\batchfile.bat' -Arguments ''
    + CategoryInfo          : ObjectNotFound: (./RunCommandLine.ps1:String) [] , CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Answer

Ansgar Wiechers picture Ansgar Wiechers · Sep 11, 2015

When running a script like ./RunCommandLine.ps1 the script is expected to be in the current working directory (.). Depending on the environment from which you're executing that statement the working directory may not be what you expect, though.

Here are some commands that allow you to determine the current working directory when run the same way as your script:

$PWD.Path
(Get-Location).Path
(Resolve-Path '.').Path

There are basically 3 ways to deal with the issue:

  • Specify the path to your PowerShell script relative to the current working directory.
  • Change the current working directory to the location of the PowerShell script:

    Push-Location 'C:\some\folder'
    .\RunCommandLine.ps1
    Pop-Location
    
  • Run the PowerShell script with its full path:

    & 'C:\some\folder\RunCommandLine.ps1'
    

    The call operator (&) allows you to run paths that are defined as strings (for instance because they contain spaces), which would otherwise just be echoed.