powershell - : The term './RunCommandLine.ps1' is not recognized as the name of a cmdlet, 函数、脚本文件或可运行程序出错

标签 powershell ms-release-management

我们正在使用 Microsoft Release Management 2013 部署到 Dev/Test/Prod。构建/部署服务器是 MS2012。应用服务器是 MS2008。我让它工作和部署,但昨天我开始收到这条消息。它所做的一切都是使用“运行命令行”在应用程序服务器上运行一个批处理文件,该文件进行备份、设置 Windows 服务启动类型、停止服务等。如果我直接在应用程序服务器上运行批处理文件,它只会运行美好的。我根据本文添加了更详细的日志记录,但没有收集其他信息以进行调试。 Powershell 最近也没有在服务器上更新。

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

任何人都知道 *.ps1 文件应该在哪里?我搜索了本地和服务器,但一无所获。有人遇到过这种情况吗?

错误信息:

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

最佳答案

当运行像 ./RunCommandLine.ps1 这样的脚本时,该脚本应该位于当前工作目录 ( . ) 中。但是,根据您执行该语句的环境,工作目录可能不是您所期望的。

以下是一些命令,可让您在以与脚本相同的方式运行时确定当前工作目录:

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

基本上有3种方法来处理这个问题:
  • 指定 PowerShell 脚本相对于当前工作目录的路径。
  • 将当前工作目录更改为 PowerShell 脚本所在的位置:
    Push-Location 'C:\some\folder'
    .\RunCommandLine.ps1
    Pop-Location
    
  • 使用完整路径运行 PowerShell 脚本:
    & 'C:\some\folder\RunCommandLine.ps1'
    

    调用运算符 ( & ) 允许您运行定义为字符串的路径(例如,因为它们包含空格),否则只会被回显。
  • 关于powershell - : The term './RunCommandLine.ps1' is not recognized as the name of a cmdlet, 函数、脚本文件或可运行程序出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32507107/

    相关文章:

    azure - Visual Studio Team Services 发布失败 - 无关变量

    powershell - 如何将参数值传递给 Invoke-Command cmdlet?

    tfs - Team Foundation Server 2017 构建和发布

    visual-studio - 发布管理导致构建失败

    azure - VSO 发布管理错误

    azure - 使用 Microsoft 发布管理部署 Azure 云服务

    Powershell - 使用 INVOKE-RESTMETHOD 通过多层 JSON 输出进行枚举

    c# - 从 C# 的 PowerShell 当前状态(或上下文)获取信息

    powershell - Azure Powershell 获取暂存云服务的公共(public) IP

    powershell - 在多个子域中使用SID搜索Active Directory用户