3

我有这个 powershell 脚本(test1.ps1)调用另一个 powershell 脚本(test2.ps1)来完成这项工作。

两个脚本文件都在同一个文件夹中

测试1.ps1

echo "from test1.ps1"

.\test2.ps1

测试2.ps1

echo "from test2.ps1"

当我在 C# 中通过创建运行空间、向管道添加命令并调用它来调用 test1.ps1 时,我收到一条错误消息,指出 “术语 '.\test2.ps1' 未被识别为 cmdlet、函数、脚本文件的名称, 或可运行的程序。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。”

4

1 回答 1

4

这两个脚本可能位于同一文件夹中,但.\test2.ps1会在与调用应用程序(即 C# 应用程序)相同的文件夹中查找 test2.ps1。

在 test.ps1 中有这个:

$scriptDir = Split-Path -parent $MyInvocation.MyCommand.Path
.$scriptdir\test2.ps1
于 2011-08-10T20:46:15.310 回答