powershell - powershell脚本无法执行
问题描述
我正在尝试运行 PS 脚本来启动需要 2 个参数才能启动的程序 (dtllst.exe)。
- 一个配置文件和
- 该程序用于的应用程序名称。
脚本将执行的当前状态写入输出文件。我正在尝试使用以下命令来执行脚本。
.\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
}
解决方案
推荐阅读
- shell - 循环运行脚本
- vba - PowerPoint 如何计算轴最大值?
- python - 为什么 str(repr(p)) 和 print(repr(p)) 不一样?
- python - 我正在研究人工神经网络。隐藏层在哪里?
- excel - VBA如何按值将对象添加到数组中
- bash - 如何在 java-key-store 中检查证书链的客户端证书?
- python - 如何在具有要求和设置的现有 python 包中使用 tox
- twig - 替换 N 次出现的字符串
- azure - Azure 集成 CICD 的最佳实践
- ruby-on-rails - 将帮助文件加载到 FactoryBot 文件中会导致“无法加载此类文件”