我有一个 C# PSObjects 集合,我想将它们传递给一个 powershell 脚本。我喜欢在管道中传递它,这样我就可以在 psfile 的进程部分中使用它。
任何人都知道这是否可能,在这种情况下。我该怎么做?
Collection<PSObject> colpsObject = new Collection<PSObject>();
PSObject obj1 = new PSObject();
obj1.Properties.Add(new PSNoteProperty("Name1", "Value1"));
obj1.Properties.Add(new PSNoteProperty("Name2", "Value2"));
colpsObject.Add(obj1);
PSObject obj2 = new PSObject();
obj2.Properties.Add(new PSNoteProperty("Name1", "Value1"));
obj2.Properties.Add(new PSNoteProperty("Name2", "Value2"));
colpsObject.Add(obj2);
PowershellRunspace rs = new PowershellRunspace(); //Custom Powershell class
rs.Open();
Command cmd = new Command(m_Script);
cmd.Parameters.Add("Username", m_userName);
cmd.Parameters.Add("Password", m_password);
rs.Add(cmd);
rs.Execute();