首页 > 解决方案 > powershell脚本无法执行

问题描述

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

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

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

.\start.ps1 cheetah_dbmover.cfg CHEETAH

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

1.ps1:“start.ps1”一词未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。
在行:1 字符:1
+ start.ps1 cheetah_dbmover.cfg 猎豹
+ ~~~~~
     + 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
}

标签: powershell

解决方案


推荐阅读