【发布时间】:2013-08-01 20:36:47
【问题描述】:
我正在编写将与基于 C# 的 Windows 窗体应用程序集成的 PS 脚本。这是我已经尝试/完成的:
我能够通过运行空间和管道运行 PS 脚本,但是当我尝试运行使用函数的脚本时遇到错误,说:“无法调用此函数,因为当前主机没有实现它。”
我已经研究过这个问题,我发现很少有人遇到过类似的问题,但是其中一个解决方案强调我需要使用(添加)以下 $ConfirmPreference = "None", ,-Confirm :$false, -Force
-
但是,当我尝试出现以下错误消息时:" Missing expression after unary operator '-'." 您可以看到我试图通过将字符串分配给变量来连接字符串,但这并没有帮助。我不知道如何解决它,有没有人有任何想法?任何帮助将不胜感激。
// create Powershell runspace Runspace runspace = RunspaceFactory.CreateRunspace(); // open it runspace.Open(); // create a pipeline and feed it the script text Pipeline pipeline = runspace.CreatePipeline(); //allow the functions to be exec string sa = "$ConfirmPreference = \"None\" "; string se = " -Confirm:$false -Force"; string s = sa +scriptText + se; pipeline.Commands.AddScript(s);
【问题讨论】:
标签: c# powershell pipeline