将哈希表从C#传递到PowerShell [英] Passing a hashtable from C# to PowerShell

查看:87
本文介绍了将哈希表从C#传递到PowerShell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将哈希表从C#作为脚本参数传递给PowerShell,但未成功.当我在PowerShell中执行脚本和参数时,它们可以正常工作,因此我假设我的错误在C#端.

I am attempting unsuccessfully to pass a hashtable from C# to PowerShell as a script parameter. The script and parameters work properly when I execute within PowerShell, so I'm assuming my error is on the C# side.

在C#中,就像在其他任何参数中一样,我只是简单地使用Command.Parameters.Add().我传递给脚本的所有其他参数都可以正确接收,但哈希表为空.

In C#, I am simply using Command.Parameters.Add() as I would for any other parameter. All the other parameters that I pass to the script are being received correctly, but the hashtable is null.

从C#方面,我尝试同时使用Hashtable对象和Dictionary< string,string>对象,但似乎都不起作用.在这两种情况下,我都已确认该对象已实例化并具有传递给PowerShell之前的值.我觉得有一个非常明显的解决方案使我瞪大了脸,但这只是没有点击.

From the C# side, I have tried using both a Hashtable object and a Dictionary<string, string> object, but neither appears to work. In both cases, I have confirmed that the object is instantiated and has values before passing to PowerShell. I feel like there's a very obvious solution staring me in the face, but it just isn't clicking.

推荐答案

您只能将字符串作为命令行参数传递.

You can only pass strings as command line parameters.

我不知道是否有限制,但是如果没有限制,则需要将哈希表转换为字符串并在PowerShell脚本中进行解析.

I don't know if there a limit but if there isn't you will need to convert the hashtable to a string and parse it in your PowerShell script.

这篇关于将哈希表从C#传递到PowerShell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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