Powershell Invoke()在C#中返回零以执行螺栓命令 [英] Powershell Invoke() returning zero in C# for bolt command run

查看:138
本文介绍了Powershell Invoke()在C#中返回零以执行螺栓命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够在Powershell中运行p命令.在powershell中,我得到如下输出

I'm able to run puppet bolt command in powershell. In powershell, I got output as below

从winrm://remotemachine开始

Started on winrm://remotemachine

在winrm://remotemachine上完成

Finished on winrm://remotemachine

STDOUT:
RemoteMachineHostName

成功完成1个目标,在3.2秒内在1个小工具上运行

Successful on 1 target Run on 1 tartget in 3.2 sec

我的C#如下

        PowerShell ps = PowerShell.Create();

        ps.AddScript("C:\\User1\\GetRemoteAzureVMHostName.ps1");

        Collection<PSObject> results =  ps.Invoke();  // in results, I'm getting value as 0.

        foreach (PSObject result in results)
        {
            //Do something
        }

我尝试在Visual Studio 2019中将构建平台目标更改为x64,但是没有用.

I tried changing build platform target to x64 in Visual Studio 2019 but it didn't worked.

如何解决上述问题

更新1:

我在powershell脚本中使用了以下命令.

I have used below command in powershell script.

bolt command run hostname --targets winrm://158.28.0.546 --no-ssl-verify --user testuser123 --password test@84p

推荐答案

我发现,Visual Studio正在调用32位Powershell,并且无法将Bot命令作为安装在64位Powershell上的Bolt模块运行.

I figured it out that, Visual Studio is calling 32 bit powershell and unable to run bolt commands as bolt module installed on 64 bit powershell.

我已将项目构建平台更改为x64并进行构建.

I have changed project build platform to x64 and build it.

有效.

这篇关于Powershell Invoke()在C#中返回零以执行螺栓命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆