c#-Windows PowerShell工作流程不适用于Process.Start()或PowerShell.Create()

问题描述 投票:1回答:1

我尝试从控制台应用程序运行Windows PowerShell工作流脚本。

方法1:

var processInfo = new System.Diagnostics.ProcessStartInfo()
{
            FileName = @"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe",
            Arguments = $"\"{scriptFile}\"",
            UseShellExecute = false               
};
System.Diagnostics.Process.Start(processInfo).WaitForExit();

方法2:

 RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
        using (Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration))
        {
            runspace.Open();
            RunspaceInvoke runspaceInvoke = new RunspaceInvoke(runspace);
            Pipeline pipeline = runspace.CreatePipeline();
            pipeline.Commands.Add(new Command(scriptFile));
            var psObjects = pipeline.Invoke();
        }

以上两种方法给我带来错误-基于Windows PowerShell的基于x86的控制台不支持Windows PowerShell工作流。打开基于Windows PowerShell基于x64的控制台,然后重试]]

方法3:

WSManConnectionInfo connectionInfo = new WSManConnectionInfo();
connectionInfo.ShellUri = "Microsoft.PowerShell.Workflow";
Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo);
runspace.Open();
PowerShell powershell = PowerShell.Create();
powershell.AddCommand(scriptFile, true);
powershell.Invoke();

方法3的错误-连接到远程服务器本地主机失败,并显示以下错误消息:拒绝访问

我有点不愿意使用Set-PSSessionConfiguration

,因为我不太了解它的后效应。我正在Windows Server 2012上运行此代码。

如何使用c#运行工作流程?

我尝试从控制台应用程序运行Windows PowerShell工作流脚本。方法1:var processInfo = new System.Diagnostics.ProcessStartInfo(){FileName = @“ C:\ Windows \ System32 \ ...

c# powershell console-application workflow process.start
1个回答
0
投票

正如问题中提到的那样,我正在使用控制台应用程序来运行Windows PowerShell工作流脚本。

© www.soinside.com 2019 - 2024. All rights reserved.