如何从引用其他脚本的C#运行Powershell脚本

如何从引用其他脚本的C#运行Powershell脚本,c#,powershell,C#,Powershell,我正在尝试从我的C#程序运行powershell脚本,如下所示: var ps = PowerShell.Create(); ps.AddScript(@"<full-path-to-script>.ps1").Invoke() var ps=PowerShell.Create(); ps.AddScript(@“.ps1”).Invoke() 但是它失败了,因为在脚本中它引用了另一个脚本,这给了我一个错误,说找不到它。但是,从命令行运行脚本可以正常工作。我不太明白为什么这在C#

我正在尝试从我的C#程序运行powershell脚本,如下所示:

var ps = PowerShell.Create();
ps.AddScript(@"<full-path-to-script>.ps1").Invoke()
var ps=PowerShell.Create();
ps.AddScript(@“.ps1”).Invoke()

但是它失败了,因为在脚本中它引用了另一个脚本,这给了我一个错误,说找不到它。但是,从命令行运行脚本可以正常工作。我不太明白为什么这在C#内部不起作用,但在命令行中起作用。有什么想法吗?

可能您有不同的工作目录。包含第二个脚本的
.ps1
内的行看起来如何?它应该使用
$PSScriptRoot

您能提供更多信息吗?喜欢.ps1中的特定部分吗?
AddScript
->
AddCommand