3
我想通过C#代码Powershell命令或脚本(什么是正确的?)变量声明添加默认值存储在C#变量中添加。 例如,在PowerShell中我打字以下行Powershell命令通过C#代码
$user = 'Admin'
我想补充的C#代码这一行。
powershell.AddScript(String.Format("$user = \"{0}\"", userName));
或
powershell.AddCommand(String.Format("$user = \"{0}\"", userName));
我尝试用AddCommand(),但它抛出异常。我使用PS 2.0。
不应该使用'AddScript'方法吗? – BartekB 2013-05-06 13:15:12