c#程序调用的Powershell脚本

本文关键字:Powershell 脚本 调用 程序 | 更新日期: 2023-09-27 18:05:25

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

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

test1.ps1

echo "from test1.ps1"
.'test2.ps1

test2.ps1

echo "from test2.ps1"

当我调用test1。通过创建运行空间,向管道添加命令并调用它,我得到一个错误消息说"术语" .'test2. "不能将Ps1 '识别为cmdlet、函数、脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后再试一次。"

c#程序调用的Powershell脚本

两个脚本可能在同一个文件夹中,但是.'test2.ps1将查找test2。

test.ps1:

$scriptDir = Split-Path -parent $MyInvocation.MyCommand.Path
.$scriptdir'test2.ps1