Powershell脚本执行失败

时间:2019-04-03 13:17:09

标签: powershell

我试图运行PS脚本来启动需要2个参数才能启动的程序(dtllst.exe)。

  1. 一个配置文件和
  2. 该程序用于的应用程序名称。

脚本将执行的当前状态写入输出文件。我正在尝试使用以下命令来执行脚本。

.\start.ps1 cheetah_dbmover.cfg CHEETAH

但是脚本失败并出现以下错误。

1.ps1 : The term 'start.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:1
+ start.ps1 cheetah_dbmover.cfg CHEETAH
+ ~~~~~
     + CategoryInfo          : ObjectNotFound: (start.ps1:String) [], CommandNotFoundException
     + FullyQualifiedErrorId : CommandNotFoundException

这是代码。

[CmdletBinding()]
Param(
    [string] $dbmover,
    [string] $appname
)

$pwd = Set-Location -Path "C:\PowerExchange"
$var = ($dbmover).Split(".")[0]

if (Test-Path "C:\PowerExchange\$appname\logs\detail.log") {
    $getfilecrtime = (Get-ChildItem "$pwd\$appname\logs\detail.log").CreationTime |
                     Get-Date -f "yyyy-MM-dd-hhmm"
    Copy-Item "$pwd\$appname\logs\detail.log" -Destination "$pwd\$appname\logs\detail_$getfilecrtime.log"
}

$config = "C:\PowerExchange\$dbmover"
$outfillepath = "C:\PowerExchange\$appname\Start\$var"
Invoke-Command -ScriptBlock {
    & cmd.exe /c C:\PowerExchange\dtllst.exe $using:config |
        Out-File -FilePath $using:outfilepath -Append
}

0 个答案:

没有答案