I need to instantiate a new object and pass it to a command input like this:
using (var pipeline = runspace.CreatePipeline())
{
// Create configuration object
pipeline.Commands.AddScript(
"$eap = New-EapConfiguration -UseWinlogonCredential");
var cmd = new Command("Add-VpnConnection");
// Set connection settings...
cmd.Parameters.Add(new CommandParameter(
"EapConfigXmlStream", "$eap.EapConfigXmlStream"));
pipeline.Commands.Add(cmd);
pipeline.Invoke();
}
Result:
Unable to convert "$eap.EapConfigXmlStream" in "System.Xml.XmlDocument" object type...
$eap.EapConfigXmlStream is interpreted as string, not as object reference
Any suggestion will be welcome
Edit:
@JohnB: This PS command works:
Set-VpnConnection -Name "MyVpnConnection"
-EapConfigXmlStream (New-EapConfiguration -UseWinlogonCredential).EapConfigXmlStream
But this C# replacement does not works:
cmd.Parameters.Add(new CommandParameter("EapConfigXmlStream",
"(New-EapConfiguration -UseWinlogonCredential).EapConfigXmlStream"));
(New-EapConfiguration -UseWinlogonCredential).EapConfigXmlStream interpreted as string
[ref]?string